我試圖通過PowerShell搜索AD以獲取基於顯示名稱的電子郵件地址。顯示名稱是我必須參考的唯一的東西。顯示名稱列表中需要的電子郵件地址
的CSV列標題是
DisplayName "John,Doe"
這裏是我運行該腳本:
$arrayDisplayNames = Import-Csv C:\3\names.csv
foreach ($objectDisplayName in $arrayDisplayNames) {
Get-Member -InputObject $objectDisplayName
$objectDisplayName.DisplayName
$stringFirstName = $objectDisplayName.DisplayName.Split(",")[0]
$stringLastName = $objectDisplayName.DisplayName.Split(",")[1]
$objectUserFromDisplay = Get-ADuser $objectDisplayName.DisplayName -Properties EmailAddress, mail
$objectUserFromFirstLast = Get-Aduser -Filter "givenName -like '$stringFirstName' -and sn -like '$stringLastName'" -Properties EmailAddress, mail
}
這裏是我的錯誤:
Get-ADuser : Cannot find an object with identity: 'John,Doe' under: 'DC=jungle,DC=com'. At line:10 char:26 + ... omDisplay = Get-ADuser $objectDisplayName.DisplayName -Properties Ema ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (John,Doe:ADUser) [Get-ADUser], ADIdentityNotFoundException + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.GetADUser Get-Aduser : The search filter cannot be recognized At line:12 char:28 + ... FirstLast = Get-Aduser -Filter "givenName -like '$stringFirstName' -a ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Get-ADUser], ADException + FullyQualifiedErrorId : ActiveDirectoryServer:8254,Microsoft.ActiveDirectory.Management.Commands.GetADUser