System Center Configuration Manager

System Center Configuration Manager (SCCM) is a client-managing tool that is primarily being used in enterprise companies with thousands of clients. Microsoft has started to make the transition from the traditional on-premises model, moving on to hybrid, up to cloud-only, scenarios. At first, this was initiated with Intune and Hybrid management. Nowadays, things are moving on to Co-management and Intune, on Azure scenarios. Due to Windows as a Service, which we also introduced in the Evergreen section in Chapter 7, Understanding PowerShell Security, SCCM is also updated very frequently. 

First, you have to set up the connection to your SCCM site server. From script, you have to import the SCCM PowerShell module, which can be accomplished as follows:

#Importing cmdlets from SCCM on the SCCM site server
Import-Module (Join-Path $(Split-Path $env:SMS_ADMIN_UI_PATH) ConfigurationManager.psd1)

#Setting location to site server
Set-Location PS1

If the site location is not recognized, you can try to add it manually with the following:

#Adding site location manually
New-PSDrive -Name [Site Code] -PSProvider "AdminUI.PS.ProviderCMSite" -Root "[FQDN of SCCM server]" -Description "SCCM Site"

The first thing to check might be the site details, as follows:

#Retrieving site information
Get-CMSite
Get-CMSite -SiteName DEV
Get-CMSite -SiteCode CM1

A detailed list of all available cmdlets can be retrieved with the following:

#Showing all cmdlets
Get-Command -Module ConfigurationManager

#Count
(Get-Command -Module ConfigurationManager).Count

PowerShell can be used within SCCM in different ways. You can execute PowerShell scripts on the SCCM servers to automate different manual tasks, but you can also use PowerShell on the client side. For this, you can embed the PowerShell scripts in the deployment itself, which can be either SCCM Applications or Packages.

Beginning with SCCM version 1802, you also have the possibility to execute PowerShell scripts on clients directly via the console, as shown in the following screenshot:

Due to the servicing of Windows and SCCM as well, many new cmdlets have been implemented and still are being implemented. As these are continuously changing, it is important that you always use the most current ones.

The following short example demonstrates the power of PowerShell within SCCM to automatically create a package from code. Most implementations of this kind will consume more dedicated time when being executed via the GUI. If you have many repetitive tasks, it is highly recommended to automate as many tasks as possible:

#Example - creating SCCM package via PowerShell
$packageInformation = @{
$Name='Test Package'
$Description='This is an example scription'
$Manufacturer='Manufacturer'
$Version = '1.0'
$Path ='\serversharedTestPackage1'
}

#Create new package with values
New-CMPackage @packageInformation
A very good code reference that contains practical examples for daily use, can be found at the following link. The repository is created by Nickolaj Andersen, MVP, and is also very well documented. It is recommended that you are familiar with System Center Configuration Manager itself before creating automation scripts, as it is a complex technology.

https://github.com/NickolajA/PowerShell/tree/master/ConfigMgr
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.84.155