The code snippet below is an example of how to recursively list all of the requirements that have been set against SCCM Applications within an environment.
Remember that technically an "Application" doesn't have requirements (such as a minimum amount of RAM or a particular Operating System)... it's a deployment type associated to an application that does. so:
- Applications have Deployment Types
- Deployment Types have "Requirements" elements
- Requirements elements may comprise of be multiple requirement rules.
... the script below lists the readable text of rules associated with applications.
[[powershell]] cls ##################################################### [string]$sSCCMServerName = "SCCMServer" [string]$SMSSiteCode = "SCCMSite" [string]$sSCCMUsername = "myusername" [string]$sSCCMPassword = "mypassword" ##################################################### # Functions # WQLConnect # Purpose: To create a WQL query connection to an SCCM Server # This will utilise credentials if script isn't being run on the server itself # function WQLConnect($Server, $User, $Password) { $namedValues = New-Object Microsoft.ConfigurationManagement.ManagementProvider.SmsNamedValuesDictionary if ($namedValues -ne $null) { write-host " namedValues object Created"} else {write-host " namedValues object Creation failed"; exit} $connection = New-Object Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine.WqlConnectionManager if ($connection -ne $null) { write-host " connection object Created"} else {write-host " connection object Creation failed"; exit} # Connect with credentials if not running on the server itself if ($env:computername.ToUpper() -eq $Server.ToUpper()){ write-host "Local WQL Connection Made" [void]$connection.Connect($Server) } else { write-host "Remote WQL Connection Made: " + $sSCCMServerName [void]$connection.Connect($Server, $User, $Password) } return $connection } ##################################################### # Main #create connection to SCCMServer $oServerConnection = WQLConnect $sSCCMServerName $sSCCMUsername $sSCCMPassword $sPath = [string]::Format("\\{0}\ROOT\sms\site_{1}", $sSCCMServerName, $SMSSiteCode) $oScope = new-object System.Management.ManagementScope -ArgumentList $sPath if ($oScope -ne $null) { write-host " oScope object Created"} else {write-host " oScope object Creation failed"; exit} $oQuery = new-object System.Management.ObjectQuery -ArgumentList ([string]"select * from sms_application where IsEnabled=1 and IsLatest=1") $oManagementObjectSearcher = new-object System.Management.ManagementObjectSearcher -ArgumentList $oScope,$oQuery $ResultsCollection = $oManagementObjectSearcher.Get() $ResultsCollectionEnumerator = $ResultsCollection.GetEnumerator() foreach ($Result in $ResultsCollection) { $Result.Get() [xml]$sdmPackageXml = New-Object system.Xml.XmlDocument $sdmPackageXml.LoadXml($Result.Properties["SDMPackageXML"].Value) Write-host "########" write-host "LocalizedDisplayName = " $Result.LocalizedDisplayName write-host "PackageID = " $Result.PackageID write-host "CI_ID = " $Result.CI_ID write-host "SoftwareVersion = " $Result.SoftwareVersion write-host "Number of Deployment Types = " $Result.NumberOfDeploymentTypes foreach ($node in $sdmPackageXml.AppMgmtDigest.DeploymentType) { write-host " DT Name = " $node.LogicalName foreach ($requirement in $node.Requirements) { foreach ($rule in $requirement.Rule) { write-host " Rule = " $requirement.Rule.Annotation.DisplayName.Text } } } write-host "" } ############################################ # Finish [[/powershell]]
- Log in to post comments