Share This Post

How To: Promote an Application Simulation to a Required Deployment in ConfigMgr 2012 SP1

A simulated deployment is a great way to validate detection rules and deployment types prior to deploying an application. In my opinion, there’s one small task that’s missing – the ability to promote a simulation to production.

This post will demonstrate how to create a right-click action on the Monitoring->Deployments tab to promote a simulation to a required deployment.


Selecting the action “Promote Simulation to Production” will launch PowerShell and display the simulation information (numbertargeted, numbersuccess, numbererrors, etc):



You can also see that by default, the script is configured to create a deadline for 8:00 PM of the date in which the script is run. Be sure to modify the script to fit your needs (as well as avoid surprises).

You can download the .zip file and follow the directions in the included ‘info.txt’ file for a fast deployment to your admin console. You can view additional details below.

First you must create the proper r-click context menu. Copy the following .xml, save it as “PromoteSIMToProd.xml”, and copy it to C:\Program Files (x86)\Microsoft Configuration Manager\AdminConsole\XmlStorage\Extensions\Actions\d1621955-48ad-4bba-9c85-95f74c0c6538\PromoteSIMtoProd.xml. (Adjust the path as appropriate to your ConfigMgr Admin Console installation path).

<br />&lt;ActionDescription DisplayName=”Promote Simulation to Production” MnemonicDisplayName=”Promote Simulation to Production” Description = “Removes Simulation and Creates Mandatory Deployment based on Simulation Config” RibbonDisplayType=”TextAndSmallImage”&gt;<br />&lt;ShowOn&gt;<br />&lt;string&gt;ContextMenu&lt;/string&gt;<br />&lt;string&gt;DefaultHomeTab&lt;/string&gt;<br />&lt;/ShowOn&gt;<br />&lt;Executable&gt;<br />&lt;FilePath&gt;PowerShell.exe&lt;/FilePath&gt;<br />-ExecutionPolicy RemoteSigned -File C:\PowerShell\CM12RClickTools\PromoteSIMToProd.ps1 “##SUB:DeploymentID##” “##SUB:__Server##” “##SUB:__Namespace##” “##SUB:CollectionID##”<br />&lt;/Executable&gt;<br />&lt;/ActionDescription&gt;<br />

Notice in the .xml that we specify the -ExeuctionPolicy RemoteSigned parameter. Best practice would be to sign your scripts, but if that’s not something you can manage easily, you can use the parameter as shown to modify the execution policy for the specific instance you’re launching, instead of changing the execution policy for all script execution. Next, copy the PowerShell code below, and save it to C:\PowerShell\CM12RClickTools\PromoteSIMToProd.ps1

<br />#capturing arguments:<br />$DeploymentID = $args[0]<br />$SiteServer = $args[1]<br />$SiteNamespace = $args[2]<br />$SiteCode = ($args[2]).Substring(14)<br />$CollectionID = $args[3]<br />$SiteDrive = $sitecode + “:”<br /><br />#”{0}, {1}, {2}, {3}, {4}, {5}” -f $DeploymentID, $SiteServer, $SiteNamespace, $CollectionID, $Sitecode, $siteDrive<br /><br />#setting a hard avail time and deadline of 20:00 on the same day the script is run.<br />##$availDate = read-host “Enter deadline date (e.g., 12/02/1973)”<br />#$availableTime = read-host “Enter deadline Time (e.g., 18:00 for 6:00pm)”<br />$availDate = (get-date).toshortdatestring()<br />$availtime = “20:00”  # if you want to configure for current time, (use get-date -format H:mm)<br />$deadlineDate = (get-date).toshortdatestring() #to specify a time in the future, just enter a date string like “12/02/2023” (with quotes)<br />$deadlineTime = “20:00″<br /><br />”Querying Simulation Information…”<br />#Connect to PowerShell Provider:<br />$ModulePath = $Env:SMS_ADMIN_UI_PATH.Replace(„\bin\i386“,“\bin\ConfigurationManager.psd1“)<br /><br />import-module $modulePath -force<br />if ((get-psdrive $siteCode -erroraction SilentlyContinue | measure).Count -ne 1) {<br />new-psdrive -Name $siteCode -PSProvider “AdminUI.PS.Provider\CMSite” -Root $SiteServer<br />}<br />cd $siteDrive<br /><br />#”{0},{1}” -f $, $Coll.membercount.Tostring()<br /><br />”Get Simulation Deployment Info”<br />$simDeploy = get-cmdeployment -deploymentid $DeploymentID<br />if ($simDeploy.DeploymentIntent -ne 3) {<br />”`nOnly Simulations can be Promoted to active deployments!`n”<br />Write-Host “Press any key to continue …”<br />$x = $host.UI.RawUI.ReadKey(“NoEcho,IncludeKeyDown”)<br />break<br />}<br />$simDeploy<br /><br />#Get Collection info, so we can show potential number of systems impacted<br />#    (for some reason, get-cmdevicecollection wasn’t dispalying membercount consistently through script)<br />$Filter = “CollectionID=’$CollectionID'”<br />$Coll = gwmi sms_collection -Namespace $SiteNamespace -ComputerName $SiteServer -filter $filter<br /><br />#Display info to admin before proceeding.<br />”`nAvailable: {0}, {1}” -f $availdate, $availtime<br />”Deadline: {0}, {1}” -f $deadlineDate, $deadlineTime<br />”Collection: {0}” -f $Coll.Name<br />”Total Collection members: {0}” -f $Coll.membercount<br /><br />#Prompt user to verify available and deadline times, and to confirm required deployment<br />$x = read-host (“Press [CTRL+C] to exit, or Press any key to create the required deployment …”)<br /><br />”Promoting Simulation to Production…”<br /><br />”Removing Simulation…”<br />remove-cmdeployment -ApplicationName $SimDeploy.SoftwareName -DeploymentID $simDeploy.DeploymentID -force<br />”Creating new Application Deployment”<br />Start-CMApplicationDeployment -CollectionName $simDeploy.CollectionName -Name $SimDeploy.SoftwareName  -AvaliableDate $availDate -AvaliableTime $availTime -Comment “Simulation Promoted to Production by $env:Username” -DeadlineDate $deadlineDate -DeadlineTime $deadlineTime -DeployAction Install -DeployPurpose Required -EnableMomAlert $True -PreDeploy $True -RaiseMomAlertsOnFailure $True -UserNotification DisplaySoftwareCenterOnly<br /><br />Write-Host “Complete. Press any key to continue …”<br /><br />$x = $host.UI.RawUI.ReadKey(“NoEcho,IncludeKeyDown”)<br />

Now re-launch your ConfigMgr Admin console to use the new r-click->Promote Simulation to Production feature. As you can see from the code, we use Get-CMDeployment to obtain the details of the simulation – and we verify it’s a simulation by DeploymentIntent=3. We then perform a WMI query to get information on the targeted collection, so that we can show the admin the total collection member count. After prompting the admin to continue, we simply call Remove-CMDeployment to remove the simulation, and then use the information previously queried and call Start-CMApplicationDeployment to deploy the application. Include additional parameters for Start-CMApplicationDeployment to standardize the deployments for your environment. For example, you could add -RaiseMomAlertsOnFailure $True -OverrideServiceWindow $True to the command line.

So as you can see, this could be a huge opportunity to ensure a consistent, automated process for application deployment.

Happy Scripting!


Share This Post

Greg Ramsey is a systems engineer specializing in global systems management for Dell Services. He has a B.S. in Computer Sciences and Engineering from the Ohio State University and is a Microsoft Most Valuable Professional (MVP) for Microsoft System Center Configuration Manager. Greg coauthored SMS 2003 Recipes: A Problem-Solution Approach (Apress, 2006) and Microsoft System Center Configuration Manager Unleashed (Sams, 2009). Greg is cofounder of the Ohio SMS Users Group, and the Central Texas Systems Management User Group.

1 Comment

  1. Hi,
    If we promote any stimulation to an actuall deployment, the copy of package to DP should be changed to automatic, can we make any modification to the powershell or add a script while promotion to do the same??

Leave a Reply