Active Directoryからユーザーを取得しようとしています。ユーザーのリストはusers.txtファイルに表示されます。私は一括クエリを行うときに、ヘッダー(列名)を保持しながら、CSV内のすべての詳細をエクスポートしたいと思います。また、errors.txtファイルのエラーを処理したい。ここで
は私のコードからの断片である:$Users = Get-Content .\users.txt
try {
$Users | Get-ADUser -Properties * | select * | Export-Csv export.csv
} catch {
$_ | Out-File errors.txt -Append
}
しかし、私が代わりにファイルに画面上のエラーを得ました。たとえば:
Get-ADUser : Cannot find an object with identity: 'admin' under: 'DC=test,DC=dev,DC=net'. At line:2 char:14 + $Users | Get-ADUser -Properties * | select * | Export-Csv export.csv + ~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (admin:ADUser) [Get-ADUser], ADIdentityNotFoundException + FullyQualifiedErrorId : ActiveDirectoryCmdlet:Microsoft.ActiveDirectory.Management.ADIdentityNotFoundException,Microsoft.ActiveDirectory.Management.Commands.GetADUser
私はCSVファイルに追加することはできませんのでforeach
のようなループを使用する必要はありません。また、私は列の名前を失う。
複数のユーザーに対して$Users | Get-ADUser
を実行すると、ファイルのエラーをどのように処理できますか?
なぜあなたはCSVに追加できませんか? –