Auditing Installed Applications on Server or PC using Powershell

Here is a simple Powershell function to audit installed apps on local or remote machine using PowerShell. The script queries the registry for installed apps rather than using Get-WMIObject as this would rerun any msi installer packages and attempt a repair (an annoying side effect). The impact of the Get-WMIObject method would mean any custom changes to the MSI i.e manual service stop or desktop shortcut would be reversed. Using the registry is a lot safer and quicker. The account used to run this script must have local administrator access and the target machine should have remote management and remote registry enabled.

to run the script use the Get-InstalledSoftware commandlet without specifying anything this will audit the local machine. Specifying the -Computername parameter targets a remote machine. Reports are HTML reports that will be written to c:\Reports on the machine this script is executed from.

Script below

Function Get-InstalledSoftware(){ 
 Param (
 [string]$ComputerName)
 $a = "<style>"
 $a = $a + "BODY{background-color:peachpuff;}"
 $a = $a + "TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;}"
 $a = $a + "TH{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:thistle}"
 $a = $a + "TD{border-width: 1px;padding: 0px;border-style: solid;border-color: black;background-color:PaleGoldenrod}"
 $a = $a + "</style><title>Installed Applications</tif folditle>"
if (!(Test-Path -Path "C:\Reports")){
 $logFolder = New-Item -Path "C:\Reports" -ItemType Directory
}else{
 $logFolder = "C:\Reports"
 }
 if (!$ComputerName ){
 Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall | Get-ItemProperty | Where-Object {$_.DisplayName} |`
 Select-Object DisplayName, Publisher, DisplayVersion, InstallDate | ConvertTo-Html -Head $a `
 -Body "<h1>Installed Applications</h1>" -As List | Out-File "$($logFolder)\installedapps.htm"
}else{
$query = Invoke-Command -ComputerName $ComputerName -ScriptBlock { Get-ChildItem HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall |`
 Get-ItemProperty | Where-Object {$_.DisplayName} |`
 Select-Object DisplayName, Publisher, DisplayVersion, InstallDate}
 $query | ConvertTo-Html -Head $a `
 -Body "<h1>Installed Applications on: $ComputerName</h1>" -as List | Out-File "$($logFolder)\$($ComputerName)_installedapps.htm"
}
}
Advertisements

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.