Deploying SCCM Applications via a custom web portal
My organisation has a user-facing application portal, distributing Application Jukebox and direct download apps from one central location. However, we use SCCM to distribute some applications and have been stuck in the unsatisfactory situation of having to direct users to two different sites depending on what application they want
- “go to the normal portal for these apps, but Software Center for these ones”. Using the method described here we can include web links directly to the application in the SCCM catalog into our existing portal- the result, we can send our users to one place, regardless of the delivery method we have chosen for that specific application.
The solution involves a PowerShell script given below (and based on some work done here). We feed it the name of the application, and some details of our SCCM environment (the site code and the Application Catalog server) and it produces a URL. This URL can then be added to our existing web portal.
In this example the script (Get-SCCM-Link.ps1
) is called with three arguments:
- Application- this is the name of the application in the SCCM Catalog we want to generate a link for.
- SiteCode- this is the sitecode of our SCCM site
- AppCatalogServer- this is the server hosting the SCCM Application Catalog
The result of running this script is a veeeery long URL. But that’s not a problem, as we’re going to place it in a web page rather than reading it out to a user over the ‘phone!
When a user clicks on the link they will be taken directly to the download page for that app in the SCCM Application Catalog as shown below. Then they just need to click “Install” and the app will be installed as normal- no need to send users to two different places or have them hunt through Software Center. The only caveat is that the application must be deployed to a User Collection of which the logged in user is a member- deploying to a Device Collection is not sufficient. But if your user can already see the app in the listing in the Application Catalog then you should be good to go.
Script
Pre-requisite: You will need the System Center Configuration Manager PowerShell Module to be available. This is installed with the Configuration Manager Console.
1Param(
2[Parameter(Mandatory=$True,Position=1)]
3[string]$Application,
4[Parameter(Mandatory=$True,Position=2)]
5[string]$SITECODE,
6[Parameter(Mandatory=$True,Position=3)]
7[string]$AppCatalogServer
8)
9
10#Start of Encode Functions
11#See http://www.nickalmiron.com/?p=30 for details
12#Dictionary values for encoding/decoding
13$codes = @{}
14$codes.Add('/', '2F00')
15$codes.Add('_', '5F00')
16$codes.Add('-', '2D00')
17$codes.Add('0', '3000')
18$codes.Add('1', '3100')
19$codes.Add('2', '3200')
20$codes.Add('3', '3300')
21$codes.Add('4', '3400')
22$codes.Add('5', '3500')
23$codes.Add('6', '3600')
24$codes.Add('7', '3700')
25$codes.Add('8', '3800')
26$codes.Add('9', '3900')
27$codes.Add('a', '6100')
28$codes.Add('b', '6200')
29$codes.Add('c', '6300')
30$codes.Add('d', '6400')
31$codes.Add('e', '6500')
32$codes.Add('f', '6600')
33$codes.Add('o', '6F00')
34$codes.Add('p', '7000')
35$codes.Add('i', '6900')
36$codes.Add('l', '6C00')
37$codes.Add('n', '6E00')
38$codes.Add('t', '7400')
39
40$upperCodes = @{}
41$upperCodes.Add('A', '4100')
42$upperCodes.Add('B', '4200')
43$upperCodes.Add('C', '4300')
44$upperCodes.Add('D', '4400')
45$upperCodes.Add('E', '4500')
46$upperCodes.Add('F', '4600')
47$upperCodes.Add('I', '4900')
48$upperCodes.Add('S', '5300')
49
50function encode([string]$AppID)
51{
52$encoded = $null
53#foreach char in string, get encoded value from dictionary
54foreach ($char in [Char[]]$AppID)
55{
56#if char is uppercase look in uppercase dictionary
57if ([char]::IsUpper($char)) { $encoded = $encoded + $upperCodes.Get_Item($char.ToString()) }
58else { $encoded = $encoded + $codes.Get_Item($char.ToString()) }
59}
60return $encoded
61}
62
63function lookUpKey($code)
64{
65$returnVal = $null
66#look in lowercase dictionary for code
67if ($codes.ContainsValue($code))
68{
69foreach ($key in ($codes.GetEnumerator() | Where-Object {$_.Value -eq $code}))
70{
71$returnVal = $key.Name
72}
73}
74#if not there look in uppercase dictionary
75elseif ($upperCodes.ContainsValue($code))
76{
77foreach ($key in ($upperCodes.GetEnumerator() | Where-Object {$_.Value -eq $code}))
78{
79$returnVal = $key.Name
80}
81}
82return $returnVal
83}
84
85function decode([string]$AppIDSig)
86{
87$i = 0
88$Code = $null
89$decoded = $null
90
91foreach ($char in [Char[]]$AppIDSig)
92{
93#if less then 4 characters in code grab next character
94if ($i -le 3)
95{
96#build 4 char codes
97$code = $code + $char
98$i++
99}
100#if 4 characters are in code lookup the decoded value
101else
102{
103$decoded = $decoded + (lookUpKey $code)
104
105#reset code and start building 4 char code again
106$code = $char
107$i = 1
108}
109}
110#foreach statement does not iterate the last time to get last code, look up value for last code here
111$decoded = $decoded + (lookUpKey $code)
112
113return $decoded
114}
115#End of Encode Functions
116
117#Import the SCCM PowerShell Module
118import-module 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1'
119#Navigate to the SCCM Site
120$SITEDRIVE= $SITECODE+":"
121CD $SITEDRIVE
122#Get the ModelName of the application
123$MyModelName=(Get-CMApplication -name "$Application").ModelName
124#Encode the ModelName string
125$MyEncodedString= encode $MyModelName
126#Build the URL
127$Result= 'http://'+$AppCatalogServer+'/CMApplicationCatalog/#/SoftwareCatalog/AppDetails/'+$MyEncodedString
128#Return the URL to the console
129$Result
Credits
- Yeah, SCCM Can Do It -The main part of the PowerShell script which encodes the important bit of the URL is based on code from this site and the next one.
- Generating CM2012 AppStore Deeplinks Using PowerShell
- Microsoft TechNet -PowerShell connecting to Configuration Manager.