Start, Cancel or Delete a SCCM Client Operation
In my last post, I demonstrated how to call the InitiateClientOperation method from the SMS_ClientOperation WMI class to run a SCEP Full Scan. However, this call itself is pretty limited for daily administration, as it requires “internal” information like the CollectionID, ResourceID or some TypeID for the Operation itself. Probably nothing you want to let some service technician deal with.
So I started to put some meat around this call and ended up with a (definitely longer than expected) script that covers the most typical tasks in regards to SCCM Client Operations.
The script called Set-ClientOperation.ps1 can be found on GitHub at https://github.com/MaikKoster/ConfigMgr/tree/master/ClientOperation. It covers three main scenarios:
1. Start a Client Operation
The syntax to start a client operation is pretty simple
Set-ClientOperation.ps1 -Start <String> [-CollectionID <String>] [-CollectionName <String>] [-ResourceID <UInt32>] [-ResourceName <String>]
The parameter Start expects one of the following values:
The purpose of each should be self-explaining.
CollectionID / CollectionName:
Either supply the CollectionID or the Collection name, but not both. If no ResourceID/ResourceName is specified, the operation will be started on all collection members.
If the CollectionID/CollectionName parameter is not specified, the script will assume the built-in “All Systems” collection (SMS00001). This is particularly helpful if you want to initiate the operation for one or very few devices. Just be aware, that at least one device needs to be specified via RessourceID/ResourceName. Otherwise one would mistakenly iniate this operation on all devices.
Set-ClientOperation.ps1 -Start QuickScan -CollectionName "All Windows 10 Machines"
ResourceID / ResourceName:
Either supply one or several ResourceIDs or Resource names, but not both.
Set-ClientOperation.ps1 -Start FullScan -ResourceName TestComputer01
2. Cancel a Client Operation
The syntax for Cancel is even shorter:
Set-ClientOperation.ps1 -Cancel -All
if you want to cancel all Client Operations. Or
Set-ClientOperation.ps1 -Cancel -OperationID <UInt32>
if only individual Client Operations shall be cancelled. The OperationID will be returned by the script when a client operation is started.
3. Delete a Client Operation
The syntax is similar to the Cancel operation:
Set-ClientOperation.ps1 -Delete -All
if you want to delete either All or
Set-ClientOperation.ps1 -Delete -Expired
all Expired/Cancelled Client Operations. Or
Set-ClientOperation.ps1 -Delete -OperationID <UInt32>
if only individual Client Operations shall be deleted. The OperationID will be returned by the script when a client operation is started.
The script supports a few additional parameters that are common for all of the above
On default the script assumes to be executed on the SCCM Site or Provider Server. You can optionally provide the Name of the Provider Server and the Site Code that shall be used.
Set-ClientOperation -Delete -All -ProviderServer CMServer01 -SiteCode XYZ
On default the script executes with the permission of the current user. You can optionally specify different credentials that shall be used to connect to the Provider Server.
$Cred = Get-Credential CMAdmin Set-ClientOperation.ps1 -Delete -All -ProviderServer CMServer01 -SiteCode XYZ -Credential $Cred
To be able to properly test this script supports the standard WhatIf parameter. If supplied, everything will be executed except the final WMI method call.
Set-ClientOperation -Delete -All -WhatIf
On default the script doesn’t write any output except the result of the WMI method call which contains the OperationID. Supply the Verbose parameter to get more information on what is being done in the script.
Set-ClientOperation -Delete -All -Verbose
To get more information please run
Get-Help Set-ClientOperation.ps1 -Detailed
The script requires at least PowerShell Version 3 and System Center Configuration Manager 2012 SP1 or above.
The script is available on GitHub. It’s published unter the MIT License and so provided “AS IS”. Even if it has been thoroughly tested, be sure to properly test it yourself before using in production. I will not be liable for any damage caused.
As always, I appreciate any comments or suggestions. Please feel free to update or extend the script if necessary.