Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Updates MEMCM configuration items with W10 supported platform rules to include the equivalent W11 rule
## Updates MEMCM configuration items with W10 supported platform rules to include the equivalent W11 rule
# Import ConfigMgr Module
Import-Module $env:SMS_ADMIN_UI_PATH.Replace('i386','ConfigurationManager.psd1')
$SiteCode = (Get-PSDrive -PSProvider CMSITE).Name
Set-Location ("$SiteCode" + ":")
$CMPSSuppressFastNotUsedCheck = $true
# Define the Windows 10 platform rules to check for
$W10RuleIds = @(
"Windows/All_ARM64_Windows_10_and_higher_Clients"
"Windows/All_MultiSession_Enterprise_Windows_10_higher"
"Windows/All_x64_Windows_10_and_higher_Clients"
)
# Get all configuration items
$ConfigurationItems = Get-CMConfigurationItem | Where {$_.LocalizedDisplayName -ne "Built-In"} | Sort LocalizedDisplayName
# Process each...
foreach ($ConfigurationItem in $ConfigurationItems)
{
Write-Output $ConfigurationItem.LocalizedDisplayName
# Get the package XML, rule nodes and rule ids
[xml]$xml = $ConfigurationItem.SDMPackageXML
$OSRuleNodes = $xml.DesiredConfigurationDigest.OperatingSystem.OperatingSystemDiscoveryRule.OperatingSystemExpression.Operands
[array]$RuleIds = $OSRuleNodes.RuleExpression.RuleId
# Proces each rule id
foreach ($RuleId in $W10RuleIds)
{
If ($RuleIds -contains $RuleId)
{
# W10 rule exists
$W11Rule = $RuleId.Replace('10','11')
If ($RuleIds -notcontains $W11Rule)
{
# Equivalent W11 rule does not exist, so add it
Write-Output "...adding rule '$W11Rule'"
If ($OSRuleNodes.RuleExpression.GetType().BaseType.Name -eq "Array")
{
$NewNode = $OSRuleNodes.RuleExpression[0].Clone()
}
else
{
$NewNode = $OSRuleNodes.RuleExpression.Clone()
}
$NewNode.RuleId = $W11Rule
[void]$OSRuleNodes.AppendChild($NewNode)
}
}
}
# Commit changes for the item
$ConfigurationItem | Set-CMConfigurationItem -DigestXml $XML.OuterXml
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment