Out-File does not show all my columns

1

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

The 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.

David Prentice

Posted 2018-03-05T17:34:16.673

Reputation: 137

You have the -wrap parameter set. What happens if you remove that one? Also, are they maybe on multiple lines? – LPChip – 2018-03-05T17:51:09.327

have you tried to pipe to Out-String -Width 4096 first before pipe to Out-File – Antony – 2018-03-06T12:47:46.607

Its funny you mentioned Out-String because I found an article yesterday after posting that covers this exact topic. https://poshoholic.com/2010/11/11/powershell-quick-tip-creating-wide-tables-with-powershell/

– David Prentice – 2018-03-06T23:48:00.513

out-file also has a width parameter, so no need for out-string (i guess) – SimonS – 2018-03-07T09:24:53.737

Answers

0

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

Clayton

Posted 2018-03-05T17:34:16.673

Reputation: 437

0

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 

Uni_x

Posted 2018-03-05T17:34:16.673

Reputation: 1