Use the Run Scripts feature in MECM (SCCM) to deploy PowerShell scripts

Run Scripts feature in MECM (SCCM) in allows you to do the following things:

  • Create and edit PowerShell scripts for use with Configuration Manager.
  • Manage script usage through roles and security scopes.
  • Run scripts on collections or individual managed devices.
  • Get Realtime script results from client devices.
  • Monitor script execution and view reporting results directly after deploying your script.

Requirements

  • To run PowerShell scripts, the client must be running PowerShell version 3.0 or later.
  • You need Configuration manager version 1706 or higher.
  • Configuration Manager clients must be running the client from the 1706 release, or higher.
  • To use scripts, you must be a member of the appropriate Configuration Manager security role.
  • To import and author scripts – Your account must have Create permissions for SMS Scripts.
  • To approve or deny scripts – Your account must have Approve permissions for SMS Scripts.
  • To run scripts – Your account must have Run Script permissions for Collections.

Lets put it in action

In the Configuration Manager console, go to the Software Library.

In the Software Library workspace, right click Scripts and click Create Script.



You must enable the Create and Run scripts feature if you don’t see the Scripts feature in the Software Library.

On the Script page of the Create Script wizard, configure the following settings:

Script Name – Enter a name for your script.
Script language – Currently, only PowerShell scripts are supported.
Import – Import a PowerShell script into the console if you already have got a PowerShell script. The script is displayed in the Script field.
Clear – Removes the current script from the Script field.
Script – Displays the currently imported script. You can edit the script in this field as necessary.

Click Next, next and Close. The new script is displayed in the Script list with a status of Waiting for approval. Before you can run this script on client devices, you must let someone approve it.

Approve the script yourself?

By default you can’t approve your own scripts, but you can change this so that you can approve your own scripts.

Open the SCCM Console

Go to your \Administration\Overview\Site Configuration\Sites\Hierarchy Settings


Uncheck the checkbox: Script authors require additional script approver



Click Ok.

Now you can approve your own script that you created.

Run a script

When the script is approve we can now run the script on a device or collection in MECM. Right click on a device or collection and select Run Script.

It is important that the device is detected as ONLINE.

If not the script won’t run and will be stuck on the creating client job.

Select the script you want to run and click Next and next again.

Now you directly see the results of the script

Or go to monitoring and select script status, select the script that has run, right click and select show status.

See Microsoft Docs for more info about the run script feature.

Theme: Overlay by Kaira