Automating SCCM global conditions with Powershell

Microsoft has added a lot of new Powershell cmdlets to Configuration Manager recently, but one thing is still notably absent from the official API, and that’s handling of global conditions, or Requirements as they are called in the GUI.

paint-requirements

A few months ago rfl_raphael posted a script on Technet that allows adding global conditions. I updated that script to support Windows 10, changed a few oddities such as allowing to run it directly from a ConfigMgr drive and fixed a few error messages. I also added two other scripts that allow reading and removing global conditions.

You can download the combined script collection here: GlobalConditionCmdlets

With these scripts you can for instance list all applications that only deploy to a primary user like this:

$applications = Get-CMApplication

$applications | % {
 $deploymenttypes = $_ | Get-CMDeploymentType

 $appname = $_.LocalizedDisplayName
 $deploymenttypes | % {
  [array]$requirements = Get-CMDeploymentTypeGlobalCondition.ps1 -ApplicationName $appname -DeploymentTypeName $_.LocalizedDisplayName

  if ($requirements.Name -like "*Primary*") {
   "Application $appname, DeploymentType $($_.LocalizedDisplayName) has"
   Write-Host ($requirements.Name) -ForegroundColor yellow
  }
 }
}

Leave a Reply

Your email address will not be published. Required fields are marked *