Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Powershell Software inventory filter

Posted on 2014-09-11
4
Medium Priority
?
380 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 1000 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 41

Accepted Solution

by:
footech earned 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
A bad practice commonly found during an account life cycle is to set its password to an initial, insecure password. The Password Reset Tool was developed to make the password reset process easier and more secure.
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 …
Screencast - Getting to Know the Pipeline

963 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