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
1 |
Set-ClientOperation.ps1 -Start <String> [-CollectionID <String>] [-CollectionName <String>] [-ResourceID <UInt32[]>] [-ResourceName <String[]>] |
Start:
The parameter Start expects one of the following values:
- FullScan
- QuickScan
- DownloadDefinition
- EvaluateSoftwareUpdates
- RequestComputerPolicy
- RequestUserPolicy
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.
1 |
Set-ClientOperation.ps1 -Start QuickScan -CollectionName "All Windows 10 Machines" |
ResourceID / ResourceName:
Either supply one or several ResourceIDs or Resource names, but not both.
1 |
Set-ClientOperation.ps1 -Start FullScan -ResourceName TestComputer01 |
2. Cancel a Client Operation
The syntax for Cancel is even shorter:
1 |
Set-ClientOperation.ps1 -Cancel -All |
if you want to cancel all Client Operations. Or
1 |
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:
1 |
Set-ClientOperation.ps1 -Delete -All |
if you want to delete either All or
1 |
Set-ClientOperation.ps1 -Delete -Expired |
all Expired/Cancelled Client Operations. Or
1 |
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.
Additional parameters
The script supports a few additional parameters that are common for all of the above
Provider information
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.
1 |
Set-ClientOperation -Delete -All -ProviderServer CMServer01 -SiteCode XYZ |
Credential
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.
1 2 |
$Cred = Get-Credential CMAdmin Set-ClientOperation.ps1 -Delete -All -ProviderServer CMServer01 -SiteCode XYZ -Credential $Cred |
WhatIf
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.
1 |
Set-ClientOperation -Delete -All -WhatIf |
Verbose
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.
1 |
Set-ClientOperation -Delete -All -Verbose |
Get-Help
To get more information please run
1 |
Get-Help Set-ClientOperation.ps1 -Detailed |
Final comments
The script requires at least PowerShell Version 3 and System Center Configuration Manager 2012 SP1 or above.
It comes with a Set-ClientOperation.Tests.ps1 file that uses Pester for Unit testing.
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.
Is it possible to use this script during a Task Sequence?
I am building a TS for building a Golden Image for VDI.
One of the things you want to do is run a full scan before you make an image of the drive.
Running your script in the VM shows a missing module named “ConfigMgr”. That sounds like the script will only run on the SCCM server, or a client running the SCCM console?
Hi Tom,
yes, the script requires a custom Module “ConfigMgr”, which is published at https://github.com/MaikKoster/ConfigMgr/tree/master/Module. Another option is to use the “Standalone” version of this script which you will find in the folder called “Standalone” at the same location as the script itself.
If you are running a task sequence anyway, it might be easier to just call mpcmdrun locally on the computer. There are command line switches for most operations. The script mentioned above would initiate this action by getting back to the ConfigMgr Provider server which then would try to connect back to the client.
Regards
Maik
For some reason it won’t let me type in the message box when I click “Antworten”.
I missed that part about the module then. I noticed the Standalone script, but wasn’t sure of the why. Now I do.
Running mpcmdrun would be my next thing. I was searching for command line running of the scan, and stumbled on your link as one of the first hits.
Reading your explanation this would be a better choice for me.
Thanks!