Executing Powershell Script Through SCCM

When executing a PowerShell script in SCCM, there are a few options you can choose from. Here are three common methods:

1. Using a Configuration Baseline
- Create a Configuration Baseline in SCCM, which contains your PowerShell script.
- Specify the PowerShell script as a configuration item within the baseline.
- Deploy the baseline to the desired collection of devices.
- SCCM will automatically evaluate the baseline on the targeted devices and execute the PowerShell script if it is not compliant.

2. Using a Package/Program
- Create a package in SCCM and include your PowerShell script file.
- Create a program within the package, specifying the command line to execute the PowerShell script (e.g., `powershell.exe -ExecutionPolicy Bypass -File "script.ps1"`).
- Deploy the package/program to the desired collection of devices.
- SCCM will distribute the package content to distribution points and initiate the execution of the PowerShell script on the targeted devices.

3. Using an Application/Deployment Type
- Create an application in SCCM and select "Script Installer" as the deployment type.
- Specify the PowerShell script as the installer script within the application.
- Configure any additional settings required, such as detection methods, requirements, and dependencies.
- Deploy the application to the desired collection of devices.
- SCCM will handle the distribution of content and execute the PowerShell script on the targeted devices based on the deployment settings.

These are general methods to execute PowerShell scripts in SCCM. The choice depends on your specific requirements and preferences. In the below example a PowerShell script package is created and deployed using the OSD task sequence.


Steps:-

Created a PowerShell script just to create a folder with machine date.(Steps shown in below mentioned screenshots).

1. Created a .cmd file and write the PowerShell script in the .cmd file so that the script can directly be executed in the command prompt.

2. Create a package containing the .cmd file and in the program part of the package give the file name just to execute the file directly in the command prompt.

3. Deploy a new machine through SCCM added the package in the Task Sequence.

4. OS will be deployed and the PowerShell script will get executed.






No comments:

Post a Comment