Create an SCCM Application using Powershell CmdLets

With SCCM 2007, I did a tool to create SCCM Packages, Programs, Collections and Advertisement using WiseScript and VBScript. But now with SCCM 2012 R2, you can use Powershell cmdlets! I had to re-do my tool with Powershell Studio.


First thing first, you need the admin console installed and you have to load the module :

$SCCMServerFQDN = ""
$SCCMSiteCode = "ABC"

import-module ($Env:SMS_ADMIN_UI_PATH.Substring(0,$Env:SMS_ADMIN_UI_PATH.Length-5) + '\ConfigurationManager.psd1') -force -erroraction SilentlyContinue
if ((get-psdrive $SCCMSiteCode -erroraction SilentlyContinue | measure).Count -ne 1) {
new-psdrive -Name $SCCMSiteCode -PSProvider "AdminUI.PS.Provider\CMSite" -Root $SCCMServerFQDN

Set-Location ABC:

From there, you can use all available Powershell cmdlets (

In my case, I decided to create an Application using an .msi. I’m also specifying a .vbs for install/uninstall (to do custom stuff before/after the installation.

New-CMApplication -Name "$ApplicationName" -Manufacturer "$Vendor" -SoftwareVersion "$AppVersion"
Add-CMDeploymentType -msiinstaller -ApplicationName $ApplicationName -DeploymentTypeName $DeploymentTypeName -AutoIdentifyFromInstallationFile -InstallationFileLocation $MsiFileLocation -ForceForUnknownPublisher $true
Set-CMDeploymentType -ApplicationName $ApplicationName -DeploymentTypeName $DeploymentTypeName -MsiOrScriptInstaller -installationProgram $installvbs -UninstallProgram $uninstallvbs -MaximumAllowedRunTimeMinutes $MaxRuntime -EstimatedInstallationTimeMinutes $EstInstTime -InstallationBehaviorType InstallForSystem -LogonRequirementType WhereOrNotUserLoggedOn -RebootBehavior NoAction -RequiresUserInteraction $false
Set-CMApplication -Name "$ApplicationName" -Description $Description

Create the Collection (with a query)

New-CMDeviceCollection -LimitingCollectionName "$LimitingCollection" -Name $CollectionName -RefreshType Periodic -RefreshSchedule $Schedule
$Query = "select SMS_R_SYSTEM.ResourceID,SMS_R_SYSTEM.ResourceType,SMS_R_SYSTEM.Name,SMS_R_SYSTEM.SMSUniqueIdentifier,SMS_R_SYSTEM.ResourceDomainORWorkgroup,SMS_R_SYSTEM.Client from ..."
Add-CMDeviceCollectionQueryMembershipRule -CollectionName $CollectionName -QueryExpression $Query -RuleName "Get Computers with ...."

Before being able to deploy the application on a collection, you must distribute the application to, at least, one server:


Start-CMContentDistribution -ApplicationName $ApplicationName -DistributionPointName $SCCMServerFQDN -DisableDetectAssociatedContentDependencies

And last step, create the deployment

$availDate = (get-date).toshortdatestring()
$availtime = get-date -format H:mm # 20:00 or if you want to configure for current time, (use get-date -format H:mm)
#$deadlineDate = (get-date).toshortdatestring() #to specify a time in the future, just enter a date string like "12/02/2023" (with quotes)
#$deadlineTime = "20:00" # 20:00 or if you want to configure for current time, (use get-date -format H:mm)
Start-CMApplicationDeployment -CollectionName $CollectionName -Name $ApplicationName -AvaliableDate $availDate -AvaliableTime $availTime -Comment "Created by $env:Username" -DeployAction Install -DeployPurpose Required -EnableMomAlert $false -PreDeploy $True -RaiseMomAlertsOnFailure $false -PersistOnWriteFilterDevice $false -UserNotification DisplayAll

2 Responses

  1. David Dowdle
    David Dowdle March 6, 2015 at 11:11 am | | Reply

    Hey Eric!
    How’s it going?
    Run into any challenges with SCCM 2012 lately?

  2. eptechinfo
    eptechinfo March 6, 2015 at 11:30 am | | Reply

    Not yet. Not enough time (well, no time) to spend on new tool. I’m looking to start working with Orchestrator, hopefully this year…

Leave a Reply