Solved

Powershell Software inventory filter

Posted on 2014-09-11
4
355 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

738 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