ConfigMgr migration script – Disable non-limited OS of Package/Programs

Posted on Updated on

Let’s say you’ve just migrated hundreds of ConfigMgr packages where the Program(s) of those packages were not previously limited. Meaning that they were set to be able to run on any and every system … including servers. That could potentially cause a HUGE outage with significant consequences in the case of an administrative goof.  Ideally in this situation, you would want/need to limit those package to the proper OS (such as All Win7 x64).

Unfortunately there are no PowerShell cmdlets that can set the OS limiting of a Program/Package.  So as a safety precaution the below PowerShell script can be used to disable any Program of migrated Packages if the Program was not limited.  In this way it can give an admin the opportunity to manually remediate the Program configuration before an accident occurs!

# By

# Site Code + :
$SiteCode = "GAL"
Set-Location $SiteCode":"

$ProgramArray = Get-CMProgram

ForEach ($Program in $ProgramArray){
    $OSCount = $Program.SupportedOperatingSystems.Count

    If ($OSCount.Equals(0)){

        if ($Program.PackageID.StartsWith($SiteCode)){
            # Do nothing
            Write-Host "Skipping non-migrated package " $Program.PackageName -ForegroundColor DarkYellow

        } ElseIf (($Program.ProgramFlags -band 0x00001000)) {
            # Program already disabled
            # Bitwise ProgramFlags operator found at
            Write-Host "Skipping disabled program " $Program.PackageName -ForegroundColor DarkYellow

        } Else {
            Write-Host "No OS limits on active package " $Program.PackageName  -ForegroundColor Red
            #Disable-CMProgram -PackageId $Program.PackageID -ProgramName $Program.ProgramName
            Write-Host "Disabled Program: " $Program.ProgramName

    } Else {
        Write-Host $OSCount " OS limits set for " $Program.PackageName " : " $Program.ProgramName -ForegroundColor DarkGreen

    Write-Host "============="

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s