輸出文件未顯示我的所有列

輸出文件未顯示我的所有列
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

某些 cmdL 只能在管道末端使用(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 

相關內容