我正在尝试通过过滤像 ** 这样的名称来使用 get-aduser 获得一个简单的功能。当我第一次运行该函数时,返回为空白。当我第二次运行它时,它返回一个双精度值。(AD 中只有一个用户)
例如:
第一次运行:没有。
第二次运行:
Name SamAccountName EmployeeID
---- -------------- ----------
John Doe john.doe 1111111
John Doe john.doe 1111111
这是代码:
function UserLookup {
$NameFirst = Read-Host "Please type in a First name"
$NameLast = Read-Host "Please type in a Last Name"
$NameLookup = "*$NameFirst* *$NameLast*"
$FormatEnumarationLimit = -1
Write-Host "Looking for "$NameLookup
Get-ADUser -SearchBase "DC=Emea" -Filter {name -like $NameLookup} -Properties * | Select name, SamAccountName, EmployeeID
}
function mn7{
Clear-Host
UserLookup
#Write-Host "USER:" $UserLookup
$answer = Read-Host "Press M to go to main menu, R to retry."
while ("M","R" -notcontains $answer)
{
$answer = Read-Host "Press M to go to main menu, R to retry."
}
if ($answer -eq 'M'){Continue :menu}
Else {mn7}
}
mn7