Check computers for installed program in powershell

Aaron picture Aaron · Dec 10, 2014 · Viewed 9k times · Source

I want to be able to look for an installed program in powershell and output to a file the results. So far, I have something that will list the install programs, and select the string that has the name of the program, but I am not sure how to specify a text file for it to use for the list of systems, and a way to make it output cleanly.

Get-WmiObject -Class Win32_Product -cn $computernamehere | Select-Object -Property Name | Sort-Object Name | Select-String Vmware | Out-File C:\Users\ajstepanik\Desktop\installed_programs.txt

I would like it to output in a fashion like:

COMPUTER1 - VMware Horizon View Client
COMPUTER2 - VMware Horizon View Client
COMPUTER3 - VMware Horizon View Client

Currently it outputs:

@{Name=VMware Horizon View Client}
@{Name=VMware Horizon View Client}
@{Name=VMware Horizon View Client}

Answer

Matt picture Matt · Dec 10, 2014

In your case I recant my previous statement about -ExpandProperty. I am still right in that it will return just a string array instead of the object property. However I think that you will have more options if you leave it as an object and just add the property "Computer" which you are looking for. That was we can just have it as a nice CSV! I am going to assume there is some loop structure here that you have not shown.

$list = Get-Content C:\Users\ajstepanik\Desktop\computers.txt
$list | ForEach-Object{
    $computer = $_
    Get-WmiObject -Class Win32_Product -ComputerName $computer | 
            Select-Object -Property Name | 
            Sort-Object Name | 
            Where-Object{$_.Name -match "Citrix"} | 
            Add-Member -MemberType NoteProperty -Name "Computer" -Value $computer -passthru
} | Export-Csv -NoTypeINformation -Path C:\temp\path.csv

Changed the select-string to a WherenMatch since i kept the object. Used Add-Member to add a property for Computer. Now we can use Export-CSV

Forgot about foreach($x in $y) doesnt work with output the way the other foreach does.