A. You can pipe Format-Table to Export-CSV, but it wonâ€™t be very pretty. All of the Format cmdlets produce a special kind of formatting objects that tell PowerShell how to construct a visual display. These objects arenâ€™t really useful to any cmdlet except an Out cmdlet. Thatâ€™s why I like to follow the rule â€śFormat Right,â€ť meaning the Format cmdlet should be the last, or right-most, cmdlet on any command line. It can be the second-last cmdlet only if itâ€™s followed by an Out cmdlet.
The good news is that thereâ€™s really no reason to pipe Format-Table to Export-CSV. Once something is in a table format, it canâ€™t become a comma-separated value (CSV) file. However, before you put it into a table format, you can use Export-CSV just fine:
Get-Service | Export-CSV
The reason a lot of people want to throw Format-Table in there is to limit the number of properties being exported:
Get-Service | Format-Table Name,DisplayName,Status | Export-CSV
That wonâ€™t work, but you can accomplish the task by using Select-Object instead:
Get-Service | Select-Object Name,DisplayName,Status | Export-CSV
Select-Object is able to pick and choose specific properties without changing the objects into those special formatting objects in the way that the Format cmdlet does.