Getting all installed applications into 1 CSV file

This topic contains 14 replies, has 5 voices, and was last updated by  js 3 months, 1 week ago.

  • Author
    Posts
  • #93271

    Mahin
    Participant

    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

    Jeremy Corbello
    Participant

    The very last line, change this:

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

    to this:

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

      Mahin
      Participant

      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

      Jeremy Corbello
      Participant

      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

      Mahin
      Participant

      Jeremy, thank you sir. That did the trick!

  • #93285

    Olaf Soyk
    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

      Mahin
      Participant

      Thank you Olaf. Your one also worked!

    • #93337

      Olaf Soyk
      Participant

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

    • #93348

      Mahin
      Participant

      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.

    • #93349

      Olaf Soyk
      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

      Mahin
      Participant

      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

      Olaf Soyk
      Participant

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

    • #93384

      Mahin
      Participant

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

  • #93427

    JohnM
    Participant

    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

    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 
    

You must be logged in to reply to this topic.