Ezine 195 - PowerShell Displays Your Installed ProgramsEzine 195 - PowerShell Displays Your Installed ProgramsLet us ask PowerShell the question, which programs are installed on this machine? I'll bet you will find at least one program that has muscled its way into your computer without your approval. Topics for PowerShell's Win32_Product
This Week's SecretI would like to remind you that most PowerShell scripts merely mimic tasks that you can perform manually. Another prime reason for scripting is to automate boring tasks. In the case of this week's script it would be tedious to wade through all the programs in the C: \Programs Files. There again, other files maybe stored in the C: \Programs Files (x86) folder, while yet more programs maybe stored who knows where. For this particular task we can also use WMIC to display a list of installed programs. Confession: I have been a little slow to embrace social networking, however, this ezine is now available at http://twitter.com/ComputerPerfGuy Mission: To List Your Installed ProgramsOur real-life task is to identify rogue programs that have persuaded you (or another user) to install them. To achieve our mission we are going to use PowerShell. Specifically, employ a WMI class called Win32_Product. Pre-requisite - Get PowerShell 2.0 from Connect
Barking Eddie's Non-PowerShell SolutionHere is Eddie's short but sweet WMI method for listing all programs installed on a computer. Go to the command prompt, and type: # Note from the command-line type: Note: Following last week's ezine you could type the above command in PowerShell, however I wanted to emphasise that WMIC an operating system command. PowerShell Equivalent to WMIC's List Installed ProgramsIn the following example we build upon the above WMI idea by researching get-WmiObject's classes. The most useful of which is Win32_Product. In truth it's not easy to improve upon Eddie's tried and trusted method of using WMIC. However, PowerShell can not only match this command-line program, but also it has features such as sort-Object and -groupBy that Eddie cannot reproduce in WMIC. # PowerShell script to list installed programs Get-WmiObject Win32_Product | Optional parameter -groupBy Get-wmiobject Win32_Product | Dissecting Win32_Product and Returning to BasicsYou could scale back this script to the simple line: get-wmiobject Win32_Product. Then add | get-Member and develop your own tactics for interrogating the extra properties available to Win32_Products. For example, append the properties, HelpLink, HelpTelephone to your basic script. See Any Updates and More PowerShell Scripts
Guy Recommends: SolarWinds Engineer's Toolset v10
|