[英]Get-ADUser -Identity
无法将变量传递给 Powershell 中的 Identity 参数。
$username = "John.Doe"
Get-ADUser -Identity "$username"
Get-ADUser : Cannot find an object with identity: 'John.Doe' under: 'DC=contoso,DC=com'.
At line:1 char:1
+ Get-ADUser -Identity "$username"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (John.Doe:ADUser) [Get-ADUser], ADIdentityNotFoundException
+ FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,M
icrosoft.ActiveDirectory.Management.Commands.GetADUser
如果我只是把 Get-ADUser -Identity "John.Doe" 放回原处就好了。
-Identity
参数接受以下内容:
- 一个独特的名字
- 一个 GUID (objectGUID)
- 安全标识符 (objectSid)
- SAM 帐户名称 (sAMAccountName)
如果要基于其他属性进行搜索,则需要使用-Filter
开关。 例如,要根据 UserPrincipalName 查找用户,您可以执行以下操作:
Get-ADUser -Filter "UserPrincipalName -eq 'John.Doe@contoso.com'"
有关更多详细信息,请参阅Get-ADUser 。
我知道这是一个老问题,但它可能是答案。 它可能会帮助一些人。 我遇到了同样的问题,这让我难住了 1 小时。 最后我使用了 $username = $username.trim() 。 所以显然变量有需要修剪的空间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.