Getting all installed applications into 1 CSV file

Welcome Forums General PowerShell Q&A Getting all installed applications into 1 CSV file

This topic contains 14 replies, has 5 voices, and was last updated by

js
 
Participant
9 months, 1 week ago.

  • Author
    Posts
  • #93271

    Participant
    Points: 20
    Rank: Member

    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
    }

  • #93277

    Participant
    Points: 22
    Rank: Member

    The very last line, change this:

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

    to this:

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

      Participant
      Points: 20
      Rank: Member

      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.

    • #93283

      Participant
      Points: 22
      Rank: Member

      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.

    • #93297

      Participant
      Points: 20
      Rank: Member

      Jeremy, thank you sir. That did the trick!

  • #93285

    Participant
    Points: 144
    Helping Hand
    Rank: Participant

    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.

    • #93300

      Participant
      Points: 20
      Rank: Member

      Thank you Olaf. Your one also worked!

    • #93337

      Participant
      Points: 144
      Helping Hand
      Rank: Participant

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

    • #93348

      Participant
      Points: 20
      Rank: Member

      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/

    • #93349

      Participant
      Points: 144
      Helping Hand
      Rank: Participant

      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
    • #93357

      Participant
      Points: 20
      Rank: Member

      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
      }
    • #93370

      Participant
      Points: 144
      Helping Hand
      Rank: Participant

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

    • #93384

      Participant
      Points: 20
      Rank: Member

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

  • #93427

    Participant
    Points: 9
    Rank: Member

    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

  • #93438
    js

    Participant
    Points: 208
    Helping Hand
    Rank: Participant

    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 
    

The topic ‘Getting all installed applications into 1 CSV file’ is closed to new replies.