PowerShell – List Local or Remote Programs with an Exclusion List of Programs

This post is to list all the software installed on your local or remote machines. The exclusion list is an array item which holds the programs  that you wanted to exclude it from displaying.

********************************************************************************

Function Get-SoftwareList {
param(
[CmdletBinding()]
[string[]]$ComputerName = $env:COMPUTERNAME
)

$writeArray=@()
$excludeArray=@()
#List of programs to exclude
$excludeArray = (“Security Update for Windows”,
“Update for Windows”,
“Update for Microsoft .NET”,
“Security Update for Microsoft”,
“Hotfix for Windows”,
“Hotfix for Microsoft .NET Framework”,
“Hotfix for Microsoft Visual Studio 2007 Tools”,
“Hotfix”)
foreach ($Computer in $ComputerName) {
$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’)
$donotwrite = $false
if (($DisplayName -ne “”) -and ($DisplayName -ne $null)) {

Foreach($exclude in $excludeArray)
{
if($DisplayName.StartsWith($exclude) -eq $TRUE)
{
$donotwrite = $true
break
}
}
if ($donotwrite -eq $false)
{
$writeArray +=New-Object -TypeName PSCustomObject -Property @{
ComputerName = $Computer
ProgramName = $DisplayName }
}
}
}

}

$column1 = @{expression=”ComputerName”; width=12; label=”ComputerName”; alignment=”left”}
$column2 = @{expression=”ProgramName”; width=120; label=”ProgramName”; alignment=”left”}
$writeArray|format-table $column1, $column2
$writeArray.GetEnumerator() | Out-GridView -Title “Software List”
}

********************************************************************************

Download here SoftwareList

Example 1 – Local Machine

PS:\>Get-SoftwareList

Example 2 -Remote computer

PS:\>Get-SoftwareList -ComputerName <COMPUTERNAME>

Example 3- Remote Computers

PS:\>Get-SoftwareList -ComputerName <COMPUTERNAME1,COMPUTERNAME2….>

Output –

SoftWareList

Advertisements

About Prashanth Jayaram

I’m a Database technologist having 11+ years of rich, hands-on experience on Database technologies. I am Microsoft Certified Professional and backed with a Degree in Master of Computer Application. My expertise lies in T-SQL programming, Replication and PowerShell You can connect me via https://social.technet.microsoft.com/profile/prashanth jayaram/ http://www.sqlshack.com/author/prashanth/ https://www.tumblr.com/blog/prashantjayaram http://www.sqlservercentral.com/blogs/powersql-by-prashanth-jayaram/ http://www.toadworld.com/members/prashanthjayaram/ My Articles are published in following sites http://www.ssas-info.com/analysis-services-articles/ http://db-pub.com/ http://www.sswug.org/sswugresearch/community/
This entry was posted in PowerShell and tagged . Bookmark the permalink.

4 Responses to PowerShell – List Local or Remote Programs with an Exclusion List of Programs

  1. dba2world says:

    excellent article , i wish you all the best for your Blog

  2. Sridar says:

    Hey Prashanth,
    When I run this script against 64 bit server it is not pulling all the installed program as you have not specified wow6432node registry key if you can add that the script will be amazing

    • Can you try this and let me know output?

      Function Get-SoftwareList {
      param(
      [CmdletBinding()]
      [string[]]$ComputerName = $env:COMPUTERNAME
      )

      $writeArray=@()
      $excludeArray=@()
      #List of programs to exclude
      $excludeArray = (“Security Update for Windows”,
      “Update for Windows”,
      “Update for Microsoft .NET”,
      “Security Update for Microsoft”,
      “Hotfix for Windows”,
      “Hotfix for Microsoft .NET Framework”,
      “Hotfix for Microsoft Visual Studio 2007 Tools”,
      “Hotfix”)
      foreach ($Computer in $ComputerName) {
      $RegBase = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,$Computer)
      $bit=(Get-WmiObject Win32_OperatingSystem -computername $computer).OSArchitecture
      if ($bit -match ’64’)
      {
      $RegUninstall=$RegBase.OpenSubKey(‘SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall’)
      write-host “64 Bit”
      $RegUninstall.GetSubKeyNames() |
      ForEach-Object {
      $DisplayName = ($RegBase.OpenSubKey(“SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\$_”)).GetValue(‘DisplayName’)
      $donotwrite = $false
      if (($DisplayName -ne “”) -and ($DisplayName -ne $null)) {

      Foreach($exclude in $excludeArray)
      {
      if($DisplayName.StartsWith($exclude) -eq $TRUE)
      {
      $donotwrite = $true
      break
      }
      }
      if ($donotwrite -eq $false)
      {
      $writeArray +=New-Object -TypeName PSCustomObject -Property @{
      ComputerName = $Computer
      ProgramName = $DisplayName }
      }
      }
      }
      }
      else
      {
      $RegUninstall = $RegBase.OpenSubKey(‘SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall’)
      write-host “32 Bit”
      $RegUninstall.GetSubKeyNames() |
      ForEach-Object {
      $DisplayName = ($RegBase.OpenSubKey(“SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\$_”)).GetValue(‘DisplayName’)
      $donotwrite = $false
      if (($DisplayName -ne “”) -and ($DisplayName -ne $null)) {

      Foreach($exclude in $excludeArray)
      {
      if($DisplayName.StartsWith($exclude) -eq $TRUE)
      {
      $donotwrite = $true
      break
      }
      }
      if ($donotwrite -eq $false)
      {
      $writeArray +=New-Object -TypeName PSCustomObject -Property @{
      ComputerName = $Computer
      ProgramName = $DisplayName }
      }
      }
      }

      }
      }
      $column1 = @{expression=”ComputerName”; width=12; label=”ComputerName”; alignment=”left”}
      $column2 = @{expression=”ProgramName”; width=120; label=”ProgramName”; alignment=”left”}
      $writeArray|format-table $column1, $column2
      $writeArray.GetEnumerator() | Out-GridView -Title “Software List”
      }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s