I wrote a powershell script for inventorying software on all PC's on a windows domain. Below I will show you how to use it and provide you with a copy of the code.
Preparation
For this program to work you will need a computer running Microsoft Powershell. Windows 7 and 2008 R2 come with powershell pre-built into them. For windows XP, 2003 and 2008 you need to manually download and install the powershell component. This PC must be a member of the domain!
Get powershell from here:
http://www.microsoft.com/windowsserver2003/technologies/management/powershell/download.mspx
Next you need to configure powershell to allow unsigned scripts to run. By default powershell is set to RemoteSigned meaning it will not run any scripts that have not been signed by an external certificate authority. To digitally sign scripts you need to buy a certificate for each piece of code you want to sign! Open powershell with administrator rights to the local system. You may have to “Run as Administrator” due to UAC!
Close the window and open another powershell window that has domain admin rights. This means you need to run the power shell window as another user. To perform “Run As” on windows 7 or Vista please see:
http://clintboessen.blogspot.com/2009/11/use-old-run-as-windows-7-and-windows.html
Running the Script
This powershell script will go through every computer account in active directory, ping the computer name, if it replies then perform the WMI query. This avoids the script failing for computers that are not turned on.
From the powershell session running as a domain admin account, navigate to the folder containing the script and run it.
You can see it will go through and skip any PC’s that are turned off. This data will get pushed into a csv which is placed in your user’s profile. Remember if you’re running as a domain admin, the csv file will be located in the domain admin user’s profile, not yours!
Reviewing the Results
Note: You must not open this file while the script is still running. This will prevent the script being able to write to it as excel takes ownership of it.
Open the CSV file up in excel and format it so it is easier to read. All the software will be listed in order along with which computer the application is installed on. Any PC’s that have any problems with WMI will not be able to perform the audit, however in a healthy windows domain all PC’s should be able to respond to WMI queries.
Script Requirement
To be able to query a PC's software you need the Management and Monitoring Tools --> WMI Windows Installer Provider windows component installed from add and remove windows components. This feature is automatically built into windows vista, 2008 and windows 7. If this is not installed the script will return the following error:
You will also recieve errors when you perform manual WMI queries related to software against these machines that do not have this component:
Don't worry I wrote up a blog post on this problem and have developed a way to mass deploy this windows component out to all PC's your trying to audit. Find this here:
http://clintboessen.blogspot.com/2009/11/wmi-error-invalid-class-0x80041010-fix.html
Copy of the Script
Here is the full copy of my script:
$datetime = Get-Date -Format "yyyyMMddhhmmss";
$strCategory = "computer";
# Create a Domain object. With no params will tie to computer domain
$objDomain = New-Object System.DirectoryServices.DirectoryEntry;
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher; # AD Searcher object
$objSearcher.SearchRoot = $objDomain; # Set Search root to our domain
$objSearcher.Filter = ("(objectCategory=$strCategory)"); # Search filter
$colProplist = "name";
foreach ($i in $colPropList)
{
$objSearcher.PropertiesToLoad.Add($i);
}
$colResults = $objSearcher.FindAll();
# Add column headers
Add-Content "$Env:USERPROFILE\softwareaudit $datetime.csv" "Computer,Caption,Description,Identifying Number,Installation Date,Installation Date 2,Installation Location,Installation State,Name,Package Cache,SKU Number,Vendor,Version";
foreach ($objResult in $colResults)
{
$objComputer = $objResult.Properties;
$computer = $objComputer.name;
$ipAddress = $pingStatus.ProtocolAddress;
# Ping the computer
$pingStatus = Get-WmiObject -Class Win32_PingStatus -Filter "Address = '$computer'";
if($pingStatus.StatusCode -eq 0)
{
Write-Host -ForegroundColor Green "Ping Reply received from $computer.";
write-host "Connecting to $computer..."
$colItems = get-wmiobject -class "Win32_Product" -namespace "root\CIMV2" `
-computername $computer
write-host "#############################"
write-host "Computer: " $computer
write-host "#############################"
write-host
write-host
foreach ($objItem in $colItems)
{
write-host "Caption: " $objItem.Caption
$caption = $objItem.Caption
write-host "Description: " $objItem.Description
$description = $objItem.Description
write-host "Identifying Number: " $objItem.IdentifyingNumber
$identifier = $objItem.IdentifyingNumber
write-host "Installation Date: " $objItem.InstallDate
$installdate = $objItem.InstallDate
write-host "Installation Date 2: " $objItem.InstallDate2
$installdate2 = $objItem.InstallDate2
write-host "Installation Location: " $objItem.InstallLocation
$installlocation = $objItem.InstallLocation
write-host "Installation State: " $objItem.InstallState
$installstate = $objItem.InstallState
write-host "Name: " $objItem.Name
$name = $objItem.Name
write-host "Package Cache: " $objItem.PackageCache
$packagecache = $objItem.PackageCache
write-host "SKU Number: " $objItem.SKUNumber
$skunumber = $objItem.SKUNumber
write-host "Vendor: " $objItem.Vendor
$vendor = $objItem.Vendor
write-host "Version: " $objItem.Version
$version = $objItem.Version
write-host
# Need to add in a special character for " as some of the values from the WMI query has commers in them that mess up the csv file
$sc = [char]34
Add-Content "$Env:USERPROFILE\softwareaudit $datetime.csv" "$sc$computer$sc,$sc$caption$sc,$sc$description$sc,$sc$identifier$sc,$sc$installdate$sc,$sc$installdate2$sc,$sc$installlocation$sc,$sc$installstate$sc,$sc$name$sc,$sc$packagecache$sc,$sc$skunumber$sc,$sc$vendor$sc,$sc$version$sc"
}
}
else
{
Write-Host -ForegroundColor Red "No Ping Reply received from $computer.";
}
}
It automatically pulls the domain information from the local computers domain membership.
Deleting old Computer Accounts
If you find there are hundreds of computer accounts that are no longer in use, and the script is sitting there pinging computer account after computer account taking ages to move through the list you may want to clean up old computer accounts in active directory.
To find all computers that have been inactive for the last four weeks and remove them run the following command on a domain controller:
dsquery computer -inactive 4 | dsrm
Tuesday, December 1, 2009
Subscribe to:
Post Comments (Atom)
Thank you so much, will definitely be useful sooner or later.
ReplyDeleteThanks for the article. Another easy way would be http://get-ps.blogspot.com/2009/11/how-to-get-installed-application-list.html
ReplyDeleteMost excellent script.
ReplyDeleteHope to learn a lot more from your examples.
Thank you very much.
Very helpful. Btw, the $ipAddress should be defined AFTER the $pingStatus is set.
ReplyDeleteAlso, I'm not a fan of prefixing the variables with their type (e.g. 'str' and 'obj'). Powershell uses objects in almost everything it does anyway, so it's redundant and makes the code a little unclear, to me.
The one place that made sense to me at first was $objComputer, but after playing with it some more, I think that since that variable is only used once, it would be more straightforward just to do:
$computer = $objResult.Properties.name
Just my two cents to add to your $100. Thanks for posting this, Clint!
Fantastic script! Already using it and pointing ppl back to this blog! One question: Can I make a minor edit and target a specific machine, such as one tha was powered off when I ran the script initially?
ReplyDeleteThanks for sharing this information about Inventory Software.
ReplyDeleteTo know about Inventory Software visit us our site HigherIdentity.Com
Thanks, i am not good on scripting, how to use it on local computer to test, please show me the modification, i will apreciate thanks :)
ReplyDeleteThis weblog website is so awesome for the guests. Thanks for talking about our journey. See more information about
ReplyDeleteaccounting software
free crack software downloads
ReplyDeleteThe great post about Software, thanks a lot for sharing.
ReplyDeleteKeep it more updates with Free Download Software
This is a great list and really important. Thank for you sharing a great article..
ReplyDeleteInventory software | Retail software
I agree with you Software Inventory Powershell Script . Such a nice post
ReplyDeleteFree Full Version Software
I like this website - its so usefull and helpfull.
ReplyDeleteFull Version Software With Crack Free Download from Celestia Jackson
This comment has been removed by the author.
ReplyDeleteThanks for sharing this information with us.
ReplyDeletedownload data rescue pc | mediacoder premium serial
its very helpful, thanks for sharing this
ReplyDeletevmware workstation portable
oh wow!! this is really nice, such a nice piece of work..............
ReplyDeletestellar phoenix activation code
this is a valuable and helpful sharing.thanks for this posting..
ReplyDeletetotal html converter serial
Thank you for this great resource!
ReplyDeleteBulk SMS Software | Bulk SMS Gateway | Voice Broadcasting
Thanks a lot for sharing this with us, was a really interesting post.
ReplyDeleteBulk SMS Software | Bulk SMS Gateway | Voice Broadcasting
Just Awesome! Kudos you are a Content Astrologer :)
ReplyDeletebest cracked software download sites|Widget for Samsung Galaxy App Android
Software Inventory Powershell Script asset management software
ReplyDeleteThank You for your information.kindly visit us: Windows Server auditing Software
ReplyDelete