In this post, you’ll learn how to connect to SCCM using PowerShell from the console, which allows running cmdlets. Connecting to Configuration Manager using PowerShell lets you run cmdlets and scripts.
Starting in ConfigMgr version 2111, the path to the module is now added to the system environment variable, PSModulePath when you install ConfigMgr console. Once you have established a PS session with SCCM, you can run PowerShell scripts to automate or extend Configuration Manager.
Thanks to Microsoft, Configuration Manager lets you use the Windows PowerShell to manage your hierarchy, including objects such as devices, users and other components. When you run Configuration Manager cmdlets by using the Configuration Manager console, your session automatically runs in the context of the site.
The Configuration Manager PowerShell module requires Microsoft .NET version 4.7.2 or later before using it. Ensure you update the dot-net framework on the SCCM server to 4.7.2 before running ConfigMgr PowerShell cmdlets.
How to Connect to SCCM using PowerShell
Perform the following steps to connect to SCCM using PowerShell from the ConfigMgr console:
- Launch the Configuration Manager console.
- In the upper-left corner, there’s a blue rectangle. Select the white arrow in the blue rectangle, and choose Connect via Windows PowerShell.
- Once you have established PS session with SCCM, you’ll see the site code which confirms that you can now run Configuration Manager cmdlets.
What you can do next is run the Get-CMSite cmdlet. This cmdlet returns information about the Configuration Manager site you’re currently connected to and any child sites. For example, the site server name, installation director, site name, and version. You can get a Configuration Manager site by using either a site name or a site code.