You can run SCCM Powershell cmdlet and scripts from the SCCM console or from a Windows PowerShell session. This is very useful to do stuff in SCCM without using the console. You can do pretty much anything using Powershell. When you get used to it, you can write more complex scripts to automate and save lots of time.

Supported versions of SCCM’s current branch support Windows PowerShell version 5.1. Starting in version 2010, the Configuration Manager PowerShell cmdlet library supports PowerShell 7

If you’re not familiar with PowerShell and SCCM, the easiest way to connect to your site is to use the shortcut in the console :

  • In the SCCM console
  • Select the upper-left white arrow choose Connect via Windows PowerShell
  • A Windows PowerShell loads, you’ll see a prompt that contains your site code. For example, if the site code is “SCD”, the prompt will show: PS SCD:\>

SCCM Powershell Cmdlet Syntax

Once connected, you can enter any SCCM Powershell cmdlet to control your site. At the time of this writing, there are hundreds of cmdlets available.

As with any Powershell cmdlet, the cmdlet is pretty self-explanatory for example the GET-CMDevice cmdlet will “GET” a “CM” (Configuration Manager), “Device” information.

Get-CMDevice -Name "CM01"

Output :

SCCM Powershell Cmdlet Examples

So here’s a couple of examples to get you started :

Get information about a specific device

Get-CMDevice – Get a Configuration Manager device.

Instead of this in the console :

 Run this :

Get-CMDevice -Name "CM01"

Output :

SCCM Powershell cmdlet

Get All Device that are not client

We will also use the Get-CMDevice cmdlet to list all non-clients. The last part Select-Object Name will only return the name of the non-clients (without the rest of the properties).

Get-CMDevice -Fast | Where-Object { $_.IsClient -eq $false } | Select-Object Name

Output :

SCCM Powershell cmdlet

Clear PXE Cache from your OSD Collection

Clear-CMPxeDeployment – Clears the status of the most recent PXE deployment in Configuration Manager.

Instead of this in the console :

3 useful Powershell commands

 Run this :

Clear-CMPxeDeployment -DeviceCollectionId "YourCollectionID"

Unlock an object

Unlock-CMObject – Release a SEDO lock on an object.

If you have a lock object and see this in the SCCM console :

3 useful Powershell commands

Run this :

Unlock-CMObject -InputObject $(Get-CMApplication -Name "Application Name")

TIP: You can change “Get-CMApplication” for “Get-CMTaskSequence” if you want to unlock a Task Sequence for example.

List collection that has Incremental update enabled

Microsoft supports only 200 collections using incremental updates. To list all collections that have incremental update enabled.

Instead of this (on each collection) :

SCCM Powershell cmdlet

Run This :

Get-CMDeviceCollection | Where{$_.RefreshType -eq 6} | Select Name

Output :

SCCM Powershell cmdlet

Add a computer to a collection (Direct Membership)

The Add-CMDeviceCollectionDirectMembershipRule cmdlet adds a direct membership rule to a device collection. A direct membership rule lets you explicitly choose the members of the device collection.

Instead of this in the console :

SCCM Powershell cmdlet

Run This :

Add-CMDeviceCollectionDirectMembershipRule -CollectionId "SCD00123" -ResourceId 2088162048

TIP: You can get the ResourceID by adding the RedsourceID column to the console

SCCM Powershell cmdlet

Remove all deployments from a specific collection

This command uses the Get-CMDeployment and Remove-CMDeployment to gets all application deployment objects for a specific collection and removes the deployments

Instead of this in the console : (on all deployment)

SCCM Powershell cmdlet

Run This :

Get-CMDeployment -CollectionName "Test - SCD" -FeatureType Application | Remove-CMDeployment -Force

SCCM Powershell Cmdlet – Update the content on a Distribution Point for an Application

Update-CMDistributionPoint – Use this cmdlet to update distribution points with the latest content

Instead of this in the console :

SCCM Powershell cmdlet

Run this :

Update-CMDistributionPoint -ApplicationName "7-zip 18.05" -DeploymentTypeName "7-zip 18.05"

Now that you know the basics, you can start writing some useful scripts to help you with your daily tasks. Get creative and automate the tasks you do the most often. SCCM Powershell cmdlet is not complicated to master, give you time and learn at your own pace. Leave your most used cmdlet in the comment section,

Comments (1)

lai290498

01.05.2024 AT 01:43 AM
Wonderful Article! - tstoto