出力ファイルにすべての列が表示されない

出力ファイルにすべての列が表示されない
Get-ADComputer -SearchBase "DC=some,DC=website,DC=net" -Filter * -Properties Name,Created,whenChanged,LastLogonDate,Description,IPv4Address,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion | Sort Description | Format-Table Name,Created,whenChanged,LastLogonDate,Description,IPv4Address,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion -Wrap  | Out-File $env:USERPROFILE\Desktop\AD-Quick-Inventory.txt

上記のコードは私が求めているものですが、.txt ファイルに出力すると、列は 5 つしかありません (説明で停止します)。

すべての列を表示できるようにするにはどうすればよいでしょうか。

export-csv を試してみたところ、必要なデータはエクスポートされましたが、選択していないランダムなプロパティも大量にエクスポートされました。

答え1

特定の cmdLets は、パイプラインの最後でのみ使用できます (Format-table、Out-File、Export-Csv)。これらの cmdLets のいずれかを使用した後、別の cmdLets を置くと、前者がオブジェクト データを文字列などの非オブジェクト データに変換しているため、ジャンクが生成されます。 を に置き換えると、format-tableselect-object選択したプロパティのみを含む CSV が得られますselect-object

Get-ADComputer -SearchBase "DC=some,DC=website,DC=net" -Filter * `
-Properties Name,Created,whenChanged,LastLogonDate,Description,IPv4Address,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion `
| Select-Object -Property Name,Created,whenChanged,LastLogonDate,Description,IPv4Address,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion `
| Sort Description | `
Export-Csv -Path AD-Quick-Inventory.csv -NoTypeInformation

答え2

次のように Get-ADComputer を csv にパイプするのはどうでしょうか:

Get-ADComputer -SearchBase "DC=some,DC=website,DC=net" -Filter * `
-Properties Name,Created,whenChanged,LastLogonDate,Description,IPv4Address,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion `
| Select-Object -Property Name,Created,whenChanged,LastLogonDate,Description,IPv4Address,OperatingSystem,OperatingSystemServicePack,OperatingSystemVersion `
| Sort Description   | ConvertTo-CSV -NoTypeInformation | Out-File $path 

関連情報