top of page
  • Writer's pictureshishir kushawaha

Trigger OSD task sequence remotely with PowerShell

This post talks about triggering the deployment from software center using PowerShell script. You may sometime need to trigger the deployment on remote system or you want to execute any specific task sequence which is advertised to client devices at once. This script helps in achieving the same.


Lets consider a scenario where you want to do the assessment of devices for their readiness for upgrade to higher version. Assessment do require to check the free space for upgrade. You have created a task sequence to achieve this. Task sequence is going to run silently. However You don't have status of some devices due to specific reason like user was on leave or device was kept offline or earlier the device was having less space but now it has enough space as informed to you . You wanted to re-run the advertisement to all such system to get the exact information. Asking every user to rerun is time consuming and not every user is technically strong. In this case , you want to trigger the advertisement or deployment silently on user's devices.


Every deployment information is stored in client's WMI repository. So you should have the required permission to access WMI on remote devices. Deployment policies are stored under root\ccm\policy\machine\actualconfig namespace under CCM_SoftwareDistribution class. You can access the namespace by running below PowerShell command.

get-wmiobject -query "SELECT * FROM CCM_SoftwareDistribution" -namespace "root\ccm\policy\machine\actualconfig" 

This will list out all the deployments assigned to device. You need to filter out the required assignment or advertisement. You can do it either by deployment package id or package name.


Sample code :


By Packageid

$Package_result=get-wmiobject-query "SELECT * FROM CCM_SoftwareDistribution" -namespace "root\ccm\policy\machine\actualconfig"|Where-Object {$_.pkg_packageid -eq $package}

By Name

$Package_result=get-wmiobject-query "SELECT * FROM CCM_SoftwareDistribution" -namespace "root\ccm\policy\machine\actualconfig"|Where-Object {$_.pkg_name -eq $package}

The result will contains instance of deployment. You need to focus on two properties of the instance.


$Package_result.ADV_MandatoryAssignments
$Package_result.ADV_RepeatRunBehavior

You need to set the values of above properties so that deployment becomes mandatory and always rerunning even if it is not originally defined.


$Package_result.ADV_MandatoryAssignments=$true
$Package_result.ADV_RepeatRunBehavior='RerunAlways'

Above values must be saved back, so run $Package_result.put() to update the local policy.


To rerun the deployment, additionally you need to know the correct scheduledMessageID. You can get it by running below command.


$sid=([xml($Package_result.PRG_Requirements)).SWDReserved.ScheduledMessageID

Once you got the proper ScheduledMessageID, trigger the deployment by below command.


([wmiclass]'ROOT\ccm:SMS_Client').TriggerSchedule($sid) | out-null

This should trigger the deployment on remote machine. This script have option to trigger deployment on single machine as well as multiple machine. Script is available at GitHub site. Please leave comment if you have any or post your queries. #MECM #SCCM #Advertisement #RemoteExecution


1,744 views0 comments

Recent Posts

See All

PowerShell Flow Control and Conditional Statements

PowerShell Flow Control and Conditional Statements are fundamental concepts that allow you to control the execution flow of your scripts based on specific conditions. They provide the flexibility to m

Comentarios


bottom of page