[英]Get-ADUser syntax error when searching against GivenName and Surname
[英]Get-ADUser - finding a user using both GivenName (FirstName) and Surname
真的很简单..
想要创建一个powershell脚本,在找到用户时返回AD结果。
我使用FirstName和Surname作为变量。 到目前为止我的脚本看起来像这样......
$FirstName = Read-Host "Please enter the First Name of the new user"
$Surname = Read-Host "Please enter the Surname of the new user"
Get-ADUser -f "GivenName -eq '$FirstName'" -and "Surname -eq '$Surname'"
当我运行Get-ADUser命令的每个部分(因此按名字搜索,按姓氏搜索)时,它返回预期的结果。
当我添加-and作为运算符,因此满足两个条件时,我得到:
Get-ADUser : A parameter cannot be found that matches parameter name 'and'.
At line:4 char:44
+ Get-ADUser -f "GivenName -eq '$FirstName'" -and "Surname -eq '$Surnam ...
+ ~~~~
+ CategoryInfo : InvalidArgument: (:) [Get-ADUser], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.ActiveDirectory.Management.
Commands.GetADUser
我到底哪里错了!?
你可以这样做:
Get-ADUser -Filter {Surname -eq "Smith" -and GivenName -eq "John"}
Get-ADUser -Filter {Surname -eq $surname -and GivenName -eq $firstname}
或这个:
Get-ADUser -Filter "Surname -eq 'Smith' -and GivenName -eq 'John'"
您的示例中的问题是您为'-and'打开了过滤器,而Get-ADUser不将其作为参数包含在内。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.