Out-File does not show all my columns
Matthew Barrera
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.txtThe above code is what I want, but when outputted to a .txt file I only have 5 columns (stopping at description).
How do I allow for all the columns to be displayed.
I tried export-csv and it did export data I wanted, but it also exported a bunch of random properties I didn't select.
42 Answers
Certain cmdLets can only be used at the end of the pipeline (Format-table, Out-File, Export-Csv). Once you use any of those cmdLets putting another after it will produce junk because the former has converted the object data to non-object data like strings, etc. If you replace format-table with select-object you will get a CSV with only the properties you've selected with 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 How about piping your Get-ADComputer to csv like this:
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