Solved

Powershell Software inventory filter

Posted on 2014-09-11
4
331 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 28

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 39

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

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
I thought I'd write this up for anyone who has a request to create an anonymous whistle-blower-type submission form created using SharePoint 2010 (this would probably work the same for 2013). It's not 100% fool-proof but it's as close as you can get…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…
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 …

759 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now