Exporting PowerShell output into .XLSX or .CSV

I have managed to get PowerShell to extract a registry key from all AD joined machines, which has been useful. However, I seem to be coming unstuck when trying to export the results into a xlsx or csv file. Is this something someone could assist with?

Get-ADComputer -Filter ‘*’ | ForEach-Object {$computername = $_.Name
Invoke-Command -computername $computername -scriptblock { Get-ItemProperty -path “HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion” | Select-Object -Property WinREVersion }}

Thanks in advance for any advice.

Hi @rob4465 and welcome to the forum.

When posting code, error messages and the like, please remember to use the Preformatted Text button to format your text as code. It’s usually hiding inside the + button on the right of the format bar.

Guide to Posting Code - Redux

Properly formatted code makes it easier for people to test what you’ve got without having to do stuff like replace double quotes and stuff that are the wrong characters when formatted normally.

It looks like you’ve got a one-liner that’s getting your registry key info. I’d recommend breaking this up especially since you’re trying to hit potentially a lot of computers and some of them may not be online and it’d be nice to handle errors for that.

But, if you want to export those resulting objects to a CSV you can use the built-in Export-Csv cmdlet.

Simply add a | at the end followed by Export-Csv ‘c:\users\YOU\Desktop\Results.csv -NoTypeInformation and you’ll have a csv file you can open in excel.

If you want to export straight to an xlsx file you’ll have to install a 3rd party module called ImportExcel, that really is quite excellent.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.