我有一个关于 Powershell 中异常的问题。由于某些原因,它们没有被捕获。
Try {
Add-ADGroupMember -Identity $GroupToModify.ObjectGUID -Members $user
} Catch [ADIdentityNotFoundException] {
#message goes here
}
尝试从不同域添加用户时,输出以下内容:
Get-ADUser : Cannot find an object with identity: 'CN=user,OU=users,
OU=J2,OU=sites,DC=asia,DC=domain,DC=com' under: 'DC=europe,
DC=domain,DC=com'.
At myscript.ps1:753 char:14
+ $adMember = Get-ADUser $user
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (CN=user...s,DC=com:ADUser)
[Get-ADUser], ADIdentityNotFoundException
+FullyQualifiedErrorId :
ActiveDirectoryCmdlet:
Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,
Microsoft.ActiveDirectory.Management.Commands.GetADUser