Monthly Archives: January 2016

Use PowerShell to list installed Software from ConfigMgr

In this blog I will share a few PowerShell functions that help me to quickly identify software installed/advertised on a client computer, as well as to list all the computers that have installed a specific application.

This script presents the list of the software installed / advertised on a client computer. Note that you have to provide info for three parameters:

  • SCCM Server name
  • WMI Namespace (the namespace always end with the 3-digit ConfigMgr site code)
  • Name of the client computer (or a file that contains computers’ names)

# PowerShell script: List-SCCMProgramsOnClientComputer.ps1
# Script to list Installed/advertised Software from ConfigMgr
# Author: Alex Dujakovic, Jan 2016
# EXAMPLE: 
# List-SCCMProgramsOnClientComputer.ps1 -SCCMName 'LAB-SCCM-001' 
#      -Namespace 'root\sms\site_ACO' -ClientName 'DART-NS-123'
# List-SCCMProgramsOnClientComputer.ps1 -SCCMName 'LAB-SCCM-001' 
#      -Namespace 'root\sms\site_ACO' -ClientName (Get-Content C:\Test\Pc.txt)
# ============================================================================
[CmdletBinding()]
	Param
        (
            [parameter(Mandatory=$True)]
            [String]
            $SCCMName,            
            
            [parameter(Mandatory=$True)]
            [String]
            $Namespace,
      
            [parameter(Mandatory=$True)]
            [String[]]
            $ClientName
        )
BEGIN{}
PROCESS{
    ForEach ($computer in $ClientName){
        Write-Host $computer -ForegroundColor Green
        If(Test-Connection -ComputerName $computer -Quiet -Count 1){   
            Get-WmiObject -ComputerName "$($SCCMName)" -Namespace "$($Namespace)" `
            -Query ("select InstalledLocation,ProductVersion,ProductName
	        from 
	            SMS_R_System
            join 
                SMS_G_SYSTEM_Installed_Software on SMS_R_System.ResourceID = 
                SMS_G_SYSTEM_Installed_Software.ResourceID
            where
                SMS_R_SYSTEM.Name= ""$($computer)"" ”) |

            Select-Object -Property ProductName, ProductVersion, InstalledLocation | 
            Sort-Object ProductName |       
            Out-GridView -Title $computer
        }
        Else {Write-Host "$computer - Ping Failed" -ForegroundColor Red }
    }
}
END {Write-Host "Done" -ForegroundColor Green}

As a result, this script presents the list of software displayed by Product Name, version and the installation location as shown in the picture below.

SCCMListAdvertisedApps

Picture 01: the GridView displays the name, version and location of installed software.

This function helps me to quickly find all computers that have installed a specific application:


# Author: Alex Dujakovic, Jan 2016
# Function ListComputersInstalledWithSoftware
# ==========================================================================
Function ListComputersInstalledWithSoftware($SCCMName, $Namespace, $SoftwareName){
Get-WmiObject -ComputerName "$($SCCMName)" -Namespace "$($Namespace)" `
-Query ("select 
	SMS_R_SYSTEM.Name
from 
	SMS_R_System 
	inner join SMS_G_System_INSTALLED_SOFTWARE on SMS_G_System_INSTALLED_SOFTWARE.ResourceID = 
    SMS_R_System.ResourceId 
where 
	SMS_G_System_INSTALLED_SOFTWARE.ARPDisplayName like ""$($SoftwareName)%"" ”)| 
    
    Select-Object -Property Name | Sort-Object Name
}
ListComputersInstalledWithSoftware -SCCMName 'LAB-SCCM-001' -Namespace "root\sms\site_ACO" `
                                   -SoftwareName "TextPad"

The following function helps me to find if specific application is installed on a particular computer.


# Author: Alex Dujakovic, Jan 2016
# Function GetInstalledSoftwareInfo
# ==========================================================================
Function GetInstalledSoftwareInfo($SCCMName, $Namespace, $SoftwareName, $ClientName){
$result = (Get-WmiObject -ComputerName "$($SCCMName)" -Namespace "$($Namespace)" `
-Query ("select 
	SMS_R_SYSTEM.Name
from 
	SMS_R_System 
	inner join SMS_G_System_INSTALLED_SOFTWARE on SMS_G_System_INSTALLED_SOFTWARE.ResourceID = 
    SMS_R_System.ResourceId 
where 
    SMS_R_SYSTEM.Name= ""$($ClientName)""
and
	SMS_G_System_INSTALLED_SOFTWARE.ARPDisplayName like ""$($SoftwareName)%"" ”))

 If($result){return "Software: $($SoftwareName) found on computer: $($ClientName)" }
 Else{return "Software: $($SoftwareName) not found on computer: $($ClientName)"}

}
GetInstalledSoftwareInfo -SCCMName 'LAB-SCCM-001' -Namespace "root\sms\site_ACO" `
                         -SoftwareName "TextPad"  -ClientName 'DART-NS-777'

As shown above, rather than using the ConfigMgr reports, you can sometimes use PowerShell scripts to efficiently retrieve information you need. All the scripts could be found in the Download section of this site.