我有一个包含特殊字符的 EN/FR 用户列表。我正在尝试获取他们的 SamAccountName,但脚本无法正常工作:
Remove-Variable * -ErrorAction SilentlyContinue; Remove-Module *; $error.Clear();
cls
$ErrorActionPreference = "STOP"
$names = Import-CSV 'C:\temp\input.csv' -Header Givenname,Surname -Delimiter ","
$CompleteReport=@()
ForEach ($Name in $Names)
{
$FirstFilter = $Name.Givenname
$SecondFilter = $Name.Surname
Write-Host $Name.Givenname, $Name.Surname
$aduser = Get-ADUser -Filter { GivenName -like $FirstFilter -and Surname -like $SecondFilter} | select enabled, GivenName, Surname, samaccountname, UserPrincipalName
$CompleteReport = $CompleteReport+$aduser
}
$CompleteReport | Export-Csv 'C:\output.csv' -NoTypeInformation
问题是我的输入列表不清楚,这导致循环继续进行而没有向我显示导致问题的项目的错误。如何捕获导致此错误的用户名?