PowerShell: Get Computer Software and Version

Posted on Updated on

Something that I have found useful in getting a hard copy of is a computers installed software, vendor and version. Today I’m just going to work with the local computer. In another post I will talk about the ability to get all software installed on a group of computers. In PowerShell there are a few ways to do what I am going to show you. The one I prefer is Get-CimInstance. I use this over Get-WMIObject becasue it gets me more information and Get-WMIObject is actually the older way from PS 2.0. It has really been replaced with Get-CimInstance. If you go to Introduction to CIM Cmdlets (MSDN Blog) you will find this quote:

“Getting/Enumerating instance of a class is the most commonly performed operation. We wanted the new Get-CimInstance Cmdlet to have better performance and even better user experience as compared to the old Get-WmiObject cmdlet. To achieve these goals we made the following design decisions:”

So, how do I write the code?

Get-ciminstance Win32_Product


Gcim Win32_Product (gcim is the alias for Get-Ciminstance)

That just spits out the information in the ugly format below:


I like my data so I can read it properly and with all the data I really want. Lets add a Piped command:

| Format-Table name, version, vendor

This gives you the results below:


Okay, so that’s nice, but how about in a CSV file that I can print or look at later? Cool, lets do it:

Gcim Win32_Product | Select-Object name, version, vendor | Export-Csv C:\software1.csv

I know, your saying wait you changed the second line from Format-Table to Select-Object and you would be correct. Why did I change it, well format-Table is for output to the console, not for something you are piping to Export-CSV. You have to Select the Objects you want to send to the CSV file to get proper data. Go ahead and try to use the Format-Table once to see you get nothing you can use in the CSV file. The output you get when you use the Select-Object is below. That’s how I would like it, how about you?


Get-Alias, What Alias?

Posted on Updated on

Yes PowerShell has aliases for its commands, a lot of them. While typing them out long hand does have intellisense and tab completion, its much easier if you get used to using the aliases of your most used commands. Even Get-Alias has an alias “gal” that will list to the console the basic information below. Figure 1 is not the complete list, just a snippet as the list is way too long, but the idea is that you can only look at it, you can’t open it and refer to it to learn them.

I exported them to a CSV using the line: gal | Export-CSV -Filename which gave me a lot more data and I just deleted the 10 rows I didn’t need. I could have went ahead and selected names to shorten the out too, but its always nice to see what PowerShell provides you. One thing it does for the Get-Alias that you don’t see is the Microsoft link to the help page for that command. See figure 2 below to see the output.

Not only save time with less typing, it gives me shortcuts to look at the whole command in a browser instead of in a console with Get-Help and needing to know the parameters that go with it.

Figure 1

CommandType Name
Alias gc  ->  Get-Content
Alias gcb  ->  Get-Clipboard
Alias gci  ->  Get-ChildItem
Alias gcm  ->  Get-Command
Alias gcs  ->  Get-PSCallStack
Alias gdr  ->  Get-PSDrive
Alias ghy  ->  Get-History
Alias gi  ->  Get-Item
Alias gjb  ->  Get-Job
Alias gl  ->  Get-Location
Alias gm  ->  Get-Member
Alias gmo  ->  Get-Module
Alias gp  ->  Get-ItemProperty
Alias gps  ->  Get-Process
Alias gpv  ->  Get-ItemPropertyValue
Alias group  ->  Group-Object
Alias gsn  ->  Get-PSSession
Alias gsnp  ->  Get-PSSnapin
Alias gsv  ->  Get-Service
Alias gu  ->  Get-Unique
Alias gv  ->  Get-Variable
Alias gwmi  ->  Get-WmiObject

Figure 2

HelpUri ResolvedCommandName Name
http://go.microsoft.com/fwlink/?LinkID=113278 Add-Content ac
http://go.microsoft.com/fwlink/?LinkID=113281 Add-PSSnapin asnp
http://go.microsoft.com/fwlink/?LinkID=113282 Clear-Content clc
http://go.microsoft.com/fwlink/?LinkID=135199 Clear-History clhy
http://go.microsoft.com/fwlink/?LinkID=225747 Clear-Host clear
http://go.microsoft.com/fwlink/?LinkID=225747 Clear-Host cls
http://go.microsoft.com/fwlink/?LinkID=113283 Clear-Item cli

Active Directory and PowerShell

Posted on Updated on

We all have added many computers to a Domain, moved them between OU’s, renamed them too. Using the Windows GUI is a tedious process with many steps. The nice thing about PowerShell is that it’s quick, easy and can be scripted to do multiple computers at one time. Even in the one computer at a time scenario it saves a few minutes a computer.

So, how do we do it? Add-Computer, Move-ADObject, Rename-Computer, Restart-Computer are all great cmdlets that make the job seamless and fast. The following command adds the local computer naming it Win10-TL to the domain called “YourDomain” and then restarts the computer to process the change in AD and on the computer immediately.

Add-Computer -ComputerName “Win10-TL” -DomainName “YourDomain” -Restart

That is way too easy for me. I need a harder way to do it so my boss thinks I’m a genius when I get things done fast and efficiently. Now, I’m all for looking like Scotty from Star Trek, but I also value my time and will look for anything that will make my job easier so that I can work on other interesting  projects.

Want to move that computer from the default Computer OU to the new OU it belongs in?

get-adcomputer Win10-TL | Move-ADObject -TargetPath ‘ou=staff computers,dc=mydomain,dc=net’

You can shorten the move command above by using other methods. One I like is placing the TargetPath into a Variable called $TP.

Work smarter, not harder.