因此,我在下面创建了这个简单的脚本片段:
$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
也不起作用。