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.

Example PowerShell

Example PowerShell to generate app URL

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.

Application Catalog

An example application in the SCCM web based catalog

Script

Pre-requisite: You will need the System Center Configuration Manager PowerShell Module to be available. This is installed with the Configuration Manager Console.

Param(
[Parameter(Mandatory=$True,Position=1)]
[string]$Application,
[Parameter(Mandatory=$True,Position=2)]
[string]$SITECODE,
[Parameter(Mandatory=$True,Position=3)]
[string]$AppCatalogServer
)

#Start of Encode Functions
#See http://www.nickalmiron.com/?p=30 for details
#Dictionary values for encoding/decoding
$codes = @{}
$codes.Add('/', '2F00')
$codes.Add('_', '5F00')
$codes.Add('-', '2D00')
$codes.Add('0', '3000')
$codes.Add('1', '3100')
$codes.Add('2', '3200')
$codes.Add('3', '3300')
$codes.Add('4', '3400')
$codes.Add('5', '3500')
$codes.Add('6', '3600')
$codes.Add('7', '3700')
$codes.Add('8', '3800')
$codes.Add('9', '3900')
$codes.Add('a', '6100')
$codes.Add('b', '6200')
$codes.Add('c', '6300')
$codes.Add('d', '6400')
$codes.Add('e', '6500')
$codes.Add('f', '6600')
$codes.Add('o', '6F00')
$codes.Add('p', '7000')
$codes.Add('i', '6900')
$codes.Add('l', '6C00')
$codes.Add('n', '6E00')
$codes.Add('t', '7400')

$upperCodes = @{}
$upperCodes.Add('A', '4100')
$upperCodes.Add('B', '4200')
$upperCodes.Add('C', '4300')
$upperCodes.Add('D', '4400')
$upperCodes.Add('E', '4500')
$upperCodes.Add('F', '4600')
$upperCodes.Add('I', '4900')
$upperCodes.Add('S', '5300')

function encode([string]$AppID)
{
$encoded = $null
#foreach char in string, get encoded value from dictionary
foreach ($char in [Char[]]$AppID)
{
#if char is uppercase look in uppercase dictionary
if ([char]::IsUpper($char)) { $encoded = $encoded + $upperCodes.Get_Item($char.ToString()) }
else { $encoded = $encoded + $codes.Get_Item($char.ToString()) }
}
return $encoded
}

function lookUpKey($code)
{
$returnVal = $null
#look in lowercase dictionary for code
if ($codes.ContainsValue($code))
{
foreach ($key in ($codes.GetEnumerator() | Where-Object {$_.Value -eq $code}))
{
$returnVal = $key.Name
}
}
#if not there look in uppercase dictionary
elseif ($upperCodes.ContainsValue($code))
{
foreach ($key in ($upperCodes.GetEnumerator() | Where-Object {$_.Value -eq $code}))
{
$returnVal = $key.Name
}
}
return $returnVal
}

function decode([string]$AppIDSig)
{
$i = 0
$Code = $null
$decoded = $null

foreach ($char in [Char[]]$AppIDSig)
{
#if less then 4 characters in code grab next character
if ($i -le 3)
{
#build 4 char codes
$code = $code + $char
$i++
}
#if 4 characters are in code lookup the decoded value
else
{
$decoded = $decoded + (lookUpKey $code)

#reset code and start building 4 char code again
$code = $char
$i = 1
}
}
#foreach statement does not iterate the last time to get last code, look up value for last code here
$decoded = $decoded + (lookUpKey $code)

return $decoded
}
#End of Encode Functions

#Import the SCCM PowerShell Module
import-module 'C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\bin\ConfigurationManager.psd1'
#Navigate to the SCCM Site
$SITEDRIVE= $SITECODE+":"
CD $SITEDRIVE
#Get the ModelName of the application
$MyModelName=(Get-CMApplication -name "$Application").ModelName
#Encode the ModelName string
$MyEncodedString= encode $MyModelName
#Build the URL
$Result= 'http://'+$AppCatalogServer+'/CMApplicationCatalog/#/SoftwareCatalog/AppDetails/'+$MyEncodedString
#Return the URL to the console
$Result

Credits


Advert:

One thought on “Deploying SCCM Applications via a custom web portal

Leave a Reply

Your email address will not be published. Required fields are marked *