Solved

Powershell Software inventory filter

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

A hard and fast method for reducing Active Directory Administrators members.
In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …
Suggested Courses

626 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