Script Examples for SCCM

One of the best features about SCCM is the ability to run PowerShell scripts directly from the console against a single device or collection. I won’t go into details on how to enable this in your environment as Microsoft already has great documentation on it: https://docs.microsoft.com/en-us/sccm/apps/deploy-use/create-deploy-scripts

The main requirements for running a script directly from the console without deploying it is to have version 1706 or higher. (It was pre-release in 1706, but is no longer pre-release starting with 1802).

I have a few very simple and effective scripts that allow me to run Scheduled Tasks on a remote computer. I can target a specific Scheduled Task, or run all Scheduled Tasks in a folder.

The first is used to run a Scheduled Task in the Root folder (Task Scheduler Library).
The second one allows you to run the scripts a Scheduled Task in the Sub folder.
The third allows you to run a script on all of the Scheduled Tasks in a folder.

  • Start-ScheduledTask -TaskName "Task Name"
  • Start-ScheduledTask -TaskPath "\Folder\SubFolder\" -TaskName "Task Name"
  • Get-ScheduledTask -TaskPath "\Folder\SubFolder\" | Start-ScheduledTask

Running the Scripts

Let’s look at the first one:
Start-ScheduledTask -TaskName "Adobe Acrobat Update Task" will run that specific taskRoot_ScheduledTasks

After running the PowerShell, you can see that only that specific Scheduled Task was run
AdobeScheduledTasksSuccessful

For the second one:
Start-ScheduledTask -TaskPath "\Microsoft\Windows\.NET Framework\" -TaskName ".NET Framework NGEN v4.0.30319"
NET_ScheduledTasks
After running the PowerShell, you can see that only that specific Scheduled Task was run
NET_ScheduledTaskSuccessful

The Third Script allows you to run all of the Scheduled Tasks in a folder.
Get-ScheduledTask -TaskPath "\Microsoft\Office\" | Start-ScheduledTask
Office_ScheduledTasks

After running the script, you can see that all of the Scheduled Tasks in Microsoft\Office have been initiated.
Office_ScheduledTasksSuccessful

These are just a few of the many ways that you can leverage the Scripts functionality in SCCM 1802 and later.

Leave a comment