PowerShell: Disabling Task Sequence ProgramFlags

If you are using Microsoft ConfigMgr 2007, you may be familiar with the ProgramFlags bit that controls the “Allow this program to be installed from the Install Software task sequence without being advertised” setting on a Program configuration. Someone on the MyITforum “mssms” mailing list recently asked how to disable this setting for all SMS programs on a given primary site server. The PowerShell code below should take care of the job for you. Please keep in mind that I have not tested this code, and am providing it only for convenience.

$SiteCode = '123'
$SccmServer = 'sccmserver'
$progs = Get-WmiObject -ComputerName $SccmServer -Namespace "rootsmssite_$SiteCode" -Class SMS_Program
$progs | ? { $_.ProgramFlags -band 1 } | % { $_.ProgramFlags -bxor 1; $_.Put() }