Contents

SCCM: Get-AppUninstallInfo - Easily creating SCCM Applications


Contents

New toys!

As mentioned before, I’ve recently started a new assignment, one that required me to design and roll out a System Center Configuration Manager solution for 4 locations.

While that wasn’t too difficult and the configuration was quite straightforward [thanks to my friends at Manning and Google], the biggest challenge came when creating packages to deploy. Luckily I was quite familiar with packaging and .MSI editing due to various MDT configurations I had made, but the latest “Current Branch” version of SCCM has “Applications”, which are smart packages [pieces of software] which you can deploy, but also uninstall if you want.

Great stuff, exactly what we needed…

The problem

If you don’t have the software in an .MSI format, you will need to manually enter various information in order for it to become “smart”, otherwise the application will only be able to install itself and possibly retry.

What kind of information do we need and where can we find it?

First, we’ll need to install the software we want to package on a dummy/test machine, so we can find certain behaviour of the program, then we need to scour the registry for the following info:

  • The DisplayName
  • The DisplayVersion
  • The UninstallString
  • The Registry Key where this is all located

The Code

Now my solution isn’t “perfect” yet, as currently I KNOW I only have to check x64 machines, but the code can be easily manipulated to do a check on system architecture :

1
(Get-WmiObject Win32_OperatingSystem).OSArchitecture

but for now it will do just fine:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
[CmdletBinding()]
Param (
    [Parameter(Mandatory=$true)]
    $ApplicationName
)

begin {
    Write-Verbose "Running $($MyInvocation.MyCommand)"
    Write-Verbose "Application is '$ApplicationName'"

    Write-Verbose 'Getting current uninstall info from Registry'
    $RegPath32 = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
    $RegPath64 = "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall"

}

process {
    Write-Verbose 'Creating new empty array'
    $AllApps = @()
    $AllApps32 = Get-ChildItem -Path $Regpath32
    $AllApps64 = Get-ChildItem -Path $RegPath64

    $AllApps += $AllApps32
    $AllApps += $AllApps64

    foreach ($App in $AllApps) {
        $AppReg = Get-ItemProperty $App.PSPath -ErrorAction SilentlyContinue | Where-Object {$_.DisplayName -like "*$ApplicationName*"}
        foreach ($wantedApp in $AppReg){
            $properties = [ordered]@{
                'DisplayName' = $WantedApp.DisplayName ;
                'DisplayVersion' = $WantedApp.DisplayVersion ;
                'UninstallString' = $WantedApp.UninstallString ;
                'RegKey' = ($WantedApp.PSPath).TrimStart('Microsoft.PowerShell.Core\Registry::')
            }
        $obj = New-Object -TypeName PSObject -Property $properties
        $obj
      }
    }
}

Simply start the script, defining the name of the application or part of it and see the magic unfold 🙂

1
.\Get-AppUninstallInfo.ps1 -ApplicationName skype -Verbose

Get-AppUninstallInfo

Happy Scripting! 🙂