无法使用Set-ADUser设置AD属性?

时间:2020-07-03 03:26:31

标签: powershell active-directory exchange-server powershell-4.0

我需要根据https://answers.microsoft.com/en-us/msoffice/forum/msoffice_o365admin-mso_exchon-mso_o365b/recipient-type-values/7c2620e5-9870-48ba-b5c2-7772c739c651

更改多个AD属性值

因此,我在下面创建了这个简单的脚本片段:

$properties = 'Name,sAMAccountName,msExchRemoteRecipientType,msExchRecipientDisplayType,msExchRecipientTypeDetails,proxyAddresses' -split ','
$ADUserAttributesValues = Get-ADUser -identity $Input -Properties $properties |
                            Select-Object Name,
                                          msExchRemoteRecipientType,
                                          msExchRecipientDisplayType,
                                          msExchRecipientTypeDetails

# Set The attributes value for Remote Shared Mailboxes
$replace = @{
    msExchRemoteRecipientType = 100
    msExchRecipientDisplayType = -2147483642
    msExchRecipientTypeDetails = 34359738368
}
Set-ADUser -Identity $ADUserAttributesValues.sAMAccountName -Replace $replace

但是,出现此错误:

Set-ADUser -Identity $ADUserAttributesValues.ToString() -Replace $replace
Set-ADUser : Cannot find an object with identity: '' under: 'DC=Domain,DC=com'.
At line:47 char:9
+         Set-ADUser -Identity $ADUserAttributesValues.ToString() -Repl ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (:ADUser) [Set-ADUser], ADIdentityNotFoundException
    + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.SetADUser

将其更改为 sAMAccountName

Set-ADUser -Identity $ADUserAttributesValues.sAMAccountName -Replace $replace
Set-ADUser : Cannot find an object with identity: '' under: 'DC=Domain,DC=com'.
At line:47 char:9
+         Set-ADUser -Identity $ADUserAttributesValues.sAMAccountName -Repl ...
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (:ADUser) [Set-ADUser], ADIdentityNotFoundException
    + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.SetADUser

也不起作用。

0 个答案:

没有答案