Author Posts

February 8, 2018 at 3:32 pm

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
}

February 8, 2018 at 3:40 pm

The very last line, change this:

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

to this:

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

February 8, 2018 at 3:42 pm

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.

February 8, 2018 at 3:47 pm

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.

February 8, 2018 at 3:55 pm

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.

February 8, 2018 at 4:14 pm

Jeremy, thank you sir. That did the trick!

February 8, 2018 at 4:16 pm

Thank you Olaf. Your one also worked!

February 8, 2018 at 11:00 pm

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

February 9, 2018 at 2:26 pm

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.

https://blogs.technet.microsoft.com/heyscriptingguy/2013/11/15/use-powershell-to-find-installed-software/

February 9, 2018 at 2:33 pm

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

February 9, 2018 at 2:47 pm

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
}

February 9, 2018 at 4:31 pm

... looks good for me ... if it get's the job done – great! 😉

February 9, 2018 at 5:02 pm

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

February 11, 2018 at 8:03 am

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

February 11, 2018 at 5:05 pm

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