SCCM Automatic Deployment Rules

Gather Auto Deployment Rules from Configuration Manager

I created this function to provide information to our team regarding the status of the Auto Deployment Rules (ADR) that have been created. This in combination with other code can be used to create mails to the team that outline the status of the various ADRs that have been running including for example the downloaded updates.

Examples:
In the below examples certain values are blurred because these are taken from a live environment.

Get-SCCMAdrs basic example showing all enabled ADRs
Get-SCCMAdrs basic example showing enabled ADR names only

Code:

Function Get-SCCMAdrs {
  <#
    .SYNOPSIS
    Returns the information from all Automatic Deployment Rules
    .DESCRIPTION
    Connects to the specified site server and retrieves the Automatic Deployment rules and their details.

    .EXAMPLE
    Get-SCCMAdrs -Enabled $True
    .EXAMPLE
    Get-SCCMAdrs -Enabled $True -SiteServer mysiteserver.example.com
    
   .PARAMETER Enabled
    The Enabled parameter is the boolean value that is used to return all enabled or disabled ADRs.
    .PARAMETER SiteServer
    The SiteServer parameter contains the name of the site server to connect with.
    .PARAMETER SiteCode
    The SiteCode parameter is optional and if not provided automatically retrieved from the specified site server.
  #>
  Param
  (
    [Parameter(Mandatory = $true)]
    [boolean]$Enabled,
    [Parameter(Mandatory = $false)]
    [string]$SiteServer = "t2sccm01.corp.tele2.com",
    [Parameter(Mandatory = $false)]
    [string]$SiteCode = (Get-WmiObject -Namespace "root\SMS" -Class SMS_ProviderLocation -ComputerName $SiteServer).SiteCode
  )
  Begin {
    Write-Verbose "Executing Function                 : $($MyInvocation.MyCommand)"
    Write-Verbose "SCCM Site Server                   : $($SiteServer)"
    Write-Verbose "SCCM Site Code                     : $($SiteCode)"
    Write-Verbose "Enabled Parameter                  : $Enabled"
  }
  Process {
    $AllAdrs = Get-WmiObject -Namespace "Root\SMS\Site_$($SiteCode)" -Class SMS_AutoDeployment -ComputerName $SiteServer | Select-Object * | Where-Object { $_.AutoDeploymentEnabled -eq $Enabled }
    If ($VerbosePreference) {
      ForEach ($ADR in $AllAdrs) {
        Write-Verbose "SCCM Automatic Deployment Rule     : $($ADR.Name)"
      }
    }
  }
  End {
    return $AllAdrs
  }
}
Posted in PowerShell, System Center Configuration Manager, WMI.

Leave a Reply

Your email address will not be published.