PowerShell- Get-ADUser筛选器问题

时间:2018-10-31 17:18:59

标签: powershell filter

PowerShell的新手,并且Get-ADUser -Filter出现问题。我认为问题与-Filter

有关
$TC_TellerID_Array = @()
$TC_TellerID_Array = Import-Csv "C:\Designer.csv"
$ADUsersArray = @()
$ADUsersArray=get-aduser -filter * -Properties * | select Name, SamAccountName, extensionAttribute1, Enabled | where extensionAttribute1 -ne $null
Foreach ($User in $ADUsersArray)
{$TrimmedTeller = ($User.extensionAttribute1).Trim()
Foreach ($TC_TellerID in $TC_TellerID_Array)
{
Get-ADUser -Filter "'$TrimmedTeller' -eq '$TC_TellerID.TellerID'" -Properties * | Select Name,SamAccountName,extensionAttribute1, Enabled
}
}

1 个答案:

答案 0 :(得分:0)

那些单引号强制使用文字字符串。正如@JosefZ指出的那样。您还希望使用SubExpression 来提取TellerID的值。尝试将代码更改为

Get-ADUser -Filter {$TrimmedTeller -eq $($TC_TellerID.TellerID)} -Properties * | Select Name,SamAccountName,extensionAttribute1, Enabled