Start a Configmgr 2007 program with powershell.
March 11th, 2011
No comments
Tried to start a ConfigMgr Program with Powershell? Then you are lucky.
Here you go:
ErrorActionPreference = "SilentlyContinue"
################################### Start a advertised program with powershell. ## ## Date: 11.06.2010 ## Written by Stian Ravndal ## Version: 0.6.5 ###################################if ($args[0] -eq "-r")
{#Reading variables from registry.$parameter1 = $args[1]
$registry = Get-ItemProperty "HKCU:\Software\Atea\StartApp\$parameter1"
$programID = $registry.ProgramID
$PackageID = $registry.PackageID
}elseif ($args[0] -eq "-s")
{# Variables is inserted from parameters.$programID = $args[1]
$PackageID = $args[2]
}else{# This will run if no parameters are specified.# Variables inserted in script.# Package ID from ConfigMgr.$PackageID = ""
# ConfigMgr ProgramID.$programID = ""
}function startapp{param ($programID, $PackageID)
if ($programID -eq "" -OR $PackageID -eq "")
{[System.Windows.Forms.MessageBox]::Show("Something wrong with parameters.")
return}else{}$startapp = New-Object -ComObject UIResource.UIResourceMgr
if ($startapp -eq $null)
{[System.Windows.Forms.MessageBox]::Show("CCM client not installed.")
return}if ($startapp.IsMandatoryProgramPending() -eq "1")
{[System.Windows.Forms.MessageBox]::Show("There is allready something running.")
return}$program = $startapp.GetProgram($programID,$PackageID)
if ($program -eq $null)
{[System.Windows.Forms.MessageBox]::Show("You do not have access to this program.")
return}$startapp.ExecuteProgram($programID, $PackageID,"")
}startapp $programID $PackageID
Categories: ConfigMgr2007, Powershell