powershellcsvregistrywindows-scriptinginstalled-applications

Powershell, Installed Software List from Registry Export Csv


been trying to get this to output to a csv. Works fine in of itself, but can't figure out how to do it. I guess because I'm using write-host it never actually goes in the pipeline which gives me a null pipeline input error. I've tried playing aroung with a few other ways to no avail. Here is the "stock code" i'd like to manage to export into a csv:

$InstalledSoftware = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall"

foreach($obj in $InstalledSoftware)
    {write-host $obj.GetValue('DisplayName') -NoNewline; 
     write-host " - " -NoNewline; 
     write-host $obj.GetValue('DisplayVersion')}

As I said, it seems like it the pipeline remains empty so adding | export-csv doesn't work. I don't even need it to write output it on screen, although it's a nice plus, so for now I'll try to reformulate it with something other than write-host.


Solution

  • You need to create first an object with the information about the specific program and the add this information to an array. Then you can export the array as an CSV. You could also export one entry at a time and append it to the csv. But if find this approach cleaner:

    $InstalledSoftware = Get-ChildItem "HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall"
    $allSoftware = [System.Collections.ArrayList]@()
    foreach($obj in $InstalledSoftware) {
        $software = New-Object -TypeName PSObject
        $software | Add-Member -MemberType NoteProperty -Name DisplayName -Value $obj.GetValue("DisplayName")
        $software | Add-Member -MemberType NoteProperty -Name Version -Value $obj.GetValue("DisplayVersion")
        $null = $allSoftware.Add($software)
    }
    
    $allSoftware | Export-Csv -Path "SomePath"