[英]Can I not use a variable in with Get-ADUser
I have a variable I pull from a form that I need to tie in with a matching display name to retrieve an existing samAccountName.我有一个从表单中提取的变量,我需要将它与匹配的显示名称联系起来以检索现有的 samAccountName。
If (Get-ADUser -Filter { (displayName -eq $user) -AND ($Returner -eq "Yes")} ) {
$Check = Get-ADUser -Filter{displayName -eq $user} -Properties SamAccountName
$sam = $check.SamAccountName
$sam
}
As soon as I have the -AND ($Returner.....) part in there the check fails to execute.只要我有 -AND ($Returner.....) 部分,检查就无法执行。
I need that check in there as that is what is passed from the Cherwell form to flag that a user is a returner and then I am going to pull in the current samAccountName for that person.我需要在那里进行检查,因为这是从 Cherwell 表单传递的内容,以标记用户是返回者,然后我将为该人提取当前的 samAccountName。
Can someone assist on how I should be using a check of a parameter in with the Get-ADUser command.有人可以帮助我如何使用 Get-ADUser 命令检查参数。
Many thanks非常感谢
S. S。
You are using $Returner
inside of the -filter
of get-aduser
.您在get-aduser
的-filter
内使用$Returner
。 If I understand correctly, this is a variable created by a form.如果我理解正确,这是一个由表单创建的变量。
You should check for $Returner
inside of the if statement:您应该在 if 语句中检查$Returner
:
If ( (Get-ADUser -Filter { displayName -eq $user}) -AND ($Returner -eq "Yes")) {
$Check = Get-ADUser -Filter{displayName -eq $user} -Properties SamAccountName
$sam = $check.SamAccountName
$sam
}
I don't see why you would perform the same Get-ADUser
command twice..我不明白你为什么要执行相同的Get-ADUser
命令两次。
You can do this like below:你可以像下面这样做:
$adUser = Get-ADUser -Filter "DisplayName -eq '$user'" -Properties DisplayName, SamAccountName
$sam = if (($adUser) -and $Returner -eq "Yes" ) { $adUser.SamAccountName }
$sam
Hope that helps希望有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.