Getting all installed applications into 1 CSV file

Hi folks. I have the code below that is correctly importing applications installed on machines and creating a new unique file for each machine with all of it’s listed installed applications (100s of files). I would like to import all the data into 1 single CSV file, instead of hundreds of individual files. Is there a way where i can import the data, so that 1 column will list the machine hostname (on the left), and to the right there will be another column that lists all the applications relevant to the specific hostname on the left column? Thanks much for your assistance

$list = Get-Content “C:\Temp\machines.txt”

foreach($node in $list){
Invoke-Command -ComputerName $node -ScriptBlock {Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Sort-Object Displayname | Format-Table –AutoSize} | Out-File C:\Temp$node.csv
}

The very last line, change this:

Out-File C:\Temp\$node.csv

to this:

Export-CSV C:\Temp\$node.csv -Append

Appreciate your reply, but that does not resolve the problem. The last line is set to create a new CSV file, since the var is $node.csv (foreach loop). -Append won’t get what i need. Thanks for your input though.

Haha, my bad. Here you go:

$list = Get-Content "C:\Temp\machines.txt"

$data = @()
foreach($node in $list){
$data += Invoke-Command -ComputerName $node -ScriptBlock {Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Select-Object DisplayName, DisplayVersion, Publisher, InstallDate | Sort-Object Displayname}
}

$data | Format-Table -AutoSize
$data | Export-Csv c:\Temp\AllMachines.csv

Create an array to save all of results to. In this instance, I used $data. Each time your foreach loop iterates, it’ll save the results to $data. At the end, you can manipulate $data however you see fit. I added 2 examples.

Here is another approach:

$list = Get-Content “C:\Temp\machines.txt”
foreach($node in $list){
Invoke-Command -ComputerName $node -ScriptBlock {
Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall* |
Select-Object DisplayName, DisplayVersion, Publisher, InstallDate, PSComputerName | Sort-Object Displayname
} | Export-Csv -Path ‘C:\Temp\Output.csv’ -Delimiter ‘,’ -NoTypeInformation -Append
}

This way you already have everything in one csv file.

Jeremy, thank you sir. That did the trick!

Thank you Olaf. Your one also worked!

Mahin,
I would like to point out that you’re catching only 32-bit applications with your query - no 64-bit applications.

Thanks Olaf for bringing that up. I’m a bit confused then, what other cmdlet would be needed to pull 64-bit applications? I included a link below from MSFT below, which shows them using the ‘Wow6432Node’ registry key. Should i point elsewhere as well? Thank you.

You don’t need another cmdlet you just need to query the 64-bit branch of the registry as well.

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall

Thanks Olaf. So something like this below?

$list = Get-Content "C:\Temp\machines.txt"
foreach($node in $list){
    Invoke-Command -ComputerName $node -ScriptBlock {
        Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | 
            Select-Object DisplayName, DisplayVersion, Publisher, InstallDate, PSComputerName | Sort-Object Displayname;
        Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | 
            Select-Object DisplayName, DisplayVersion, Publisher, InstallDate, PSComputerName | Sort-Object Displayname
    }  | Export-Csv -Path 'C:\Temp\Output.csv' -Delimiter ',' -NoTypeInformation -Append
}

… looks good for me … if it get’s the job done - great! :wink:

Thanks Olaf, i am now seeing additional 64-bit apps listed!

Check out this link to a clever way to look in both locations for 32 and 64 bit software.
http://techibee.com/powershell/powershell-script-to-query-softwares-installed-on-remote-computer/1389

You could have piped the foreach to export-csv, but the bugaboo in powershell is you have to use the other version of foreach since you can’t pipe from powershell statements:

$list | foreach {
  $node = $_
  Invoke-Command -ComputerName $node -ScriptBlock {
    Get-ItemProperty HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\* | 
      Select-Object DisplayName, DisplayVersion, Publisher, InstallDate, PSComputerName | 
      Sort-Object Displayname
    Get-ItemProperty HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | 
      Select-Object DisplayName, DisplayVersion, Publisher, InstallDate, PSComputerName | 
      Sort-Object Displayname
  } 
} | Export-Csv -Path 'C:\Temp\Output.csv' -NoTypeInformation