Solved

Powershell Software inventory filter

Posted on 2014-09-11
4
345 Views
Last Modified: 2014-09-24
Hi,

I have this script that gives me all the programs that are installed on remote computers in the network.
It works really great, except for one thing. It gives me also all the MS updates and I'm not really interested in that.
In the output the script produces, the updates do have one common value: (KB
Is there a way that I can manipulate the output, so it shows all the installed programs, except everything that has "(KB" in it's value ?

import-module activedirectory

$Computers = Get-ADComputer -Filter * -SearchBase "OU=Computers,DC=company,DC=lan" -properties SamAccountName | `
Select -ExpandProperty samaccountname
$Computername = $Computers.Replace("$","")
  
foreach ($Computer in $ComputerName) {
	if ( Test-Connection -ComputerName $Computer -Count 1 -ErrorAction SilentlyContinue ){
	$Export = "C:\Scripts\Software_Inventory\CSV\$Computer.csv"
		write-host "$Computer is pingable"
        $RegBase = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,$Computer)
        $RegUninstall = $RegBase.OpenSubKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall')
        $RegUninstall.GetSubKeyNames() | 
        ForEach-Object {
            $DisplayName = ($RegBase.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$_")).GetValue('DisplayName')
            if ($DisplayName) {
                New-Object -TypeName PSCustomObject -Property @{
                    ComputerName = $Computer
                    ProgramName = $DisplayName
					}
                }
            }| Sort-Object "ProgramName" | Export-Csv $Export -nti -delimiter ";"

Open in new window

0
Comment
Question by:Loyall
4 Comments
 
LVL 8

Expert Comment

by:Leo
ID: 40318722
I am after the same question, would be keen to find out, how it can be achieved.....
0
 
LVL 29

Assisted Solution

by:becraig
becraig earned 250 total points
ID: 40318723
You could make a simple change based on how the KB values are displayed

import-module activedirectory

$Computers = Get-ADComputer -Filter * -SearchBase "OU=Computers,DC=company,DC=lan" -properties SamAccountName | `
Select -ExpandProperty samaccountname
$Computername = $Computers.Replace("$","")
  
foreach ($Computer in $ComputerName) {
	if ( Test-Connection -ComputerName $Computer -Count 1 -ErrorAction SilentlyContinue ){
	$Export = "C:\Scripts\Software_Inventory\CSV\$Computer.csv"
		write-host "$Computer is pingable"
        $RegBase = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,$Computer)
        $RegUninstall = $RegBase.OpenSubKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall')
        $RegUninstall.GetSubKeyNames() | 
        ForEach-Object {
            $DisplayName = ($RegBase.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$_")).GetValue('DisplayName')
            if ($DisplayName -note like "*(KB*" -and $Displayname -ne $null) {
                New-Object -TypeName PSCustomObject -Property @{
                    ComputerName = $Computer
                    ProgramName = $DisplayName
					}
                }
            }| Sort-Object "ProgramName" | Export-Csv $Export -nti -delimiter ";"
                                  

Open in new window


The code above is based on the assumption as you indicate that KBS have "(KB" in their name, as such we exclude them from the results.
0
 
LVL 40

Accepted Solution

by:
footech earned 250 total points
ID: 40319134
If you want a listing that is the same as what you see when you open "Program and Features" in the Control Panel, query for a couple more properties besides DisplayName (namely systemcomponent and parentkeyname), and then you can filter as shown in the example below.
$list = Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall
$list | Get-ItemProperty -Name displayname,systemcomponent,parentkeyname -ErrorAction SilentlyContinue |
 ? { !($_.systemcomponent) -and !($_.Parentkeyname) }

Open in new window

0
 
LVL 2

Author Comment

by:Loyall
ID: 40319206
Hi, thanks for your replies, I will adjust and test the script ans than let you know !
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
This article explains the steps required to use the default Photos screensaver to display branding/corporate images
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question