July 7, 2009 / by Jeffery Hicks / Windows PowerShell / No Comments

July PowerShell One-Liner

Search01 This month’s PowerShell one-liner queries the WMI Win32_Product class for a specified computer and builds a formatted report of all installed applications sorted by vendor. You’ll be able to tell at a glance what is installed, when it was installed, where it was installed from and the product version. Be warned that querying this WMI class may take several minutes or longer.

This one line expression defaults to the local computer, but you can substitute any computername you want. You can also add support for alternate credentials. I’ve broken the expression into several lines for publication purposes but this is in fact a oneline expression.

This has been tested on both PowerShell v1 and v2.

Get-WmiObject win32_product -computer $env:computername | 
sort Vendor,InstallDate | 
Format-Table -GroupBy Vendor Name,`
@{Label="InstallDate";Expression={
"$($_.InstallDate.substring(4,2))/$($_.InstallDate.substring(6,2))/$($_.InstallDate.substring(0,4))"}},`
InstallLocation,InstallSource,PackageName,Version -wrap | 
Out-File productreport.txt

I probably could have left the InstallDate alone since a value like 20090511 isn’t too hard to figure out, but I took the extra step to parse and reorder so that you get a friendlier value of 05/11/2009. Of course if you have different regional settings you might need to tweak my substring parsing.

The oneliner builds a formatted report, but you could easily modify it to use Select-Object instead so that you could export to a CSV, build an HTML report or whatever you require.

There is a wealth of information in this class. Here are some other ways you might want leverage this class:

$products=Get-WmiObject win32_product -computer $env:computername
$products | sort InstallDate | Select Name,InstallDate,Vendor,Version
$products | group vendor | sort count -descending | Select Count,Name
$products | Where {$_.vendor -like "SAPIEN*"} | Sort Name | Select Name,Version,InstallDate,InstallSource,PackageName

Download a script file with these expressions here.

Enjoy!

RSS SAPIEN Info Center

Search the Archives

Join our mailing list

Enter your email address to subscribe to our mailing lists for Monthly Blog Digests, Product Announcements and more (you can choose which you receive once you sign-up!)

Tags

Categories

Archives

BlogRoll

PowerShell Links

Information

Dashboard