Set Advertisement settings using powershell

Hi,

I need to change multiple advertisements with a powershell script. All advertisements have a mandatory assignment configured, and I need to check the "Ignore maintenance windows" and set the Rerun Behavior as "Always rerun". I created a powershell script that read the advertisements names from a file and change each one. The problem is: When I run the script, the mandatory assignment is removed from advertisement! Any ideas how to fix it?

#Get Advertisement name from txt file

$Source = Get-Content c:\temp\AdvertName.txt
#Set counter to 0
$Count = 0
#For each advertisement in source file, change Properties as needed and increment counting
Foreach ($AdvertName in $Source)
{
#Connect to SCCM server using WMI and filter advertisement by name present in source file
$Advert = Get-WmiObject -ComputerName SCCMSERVER -Namespace "root\sms\site_SCCM" -class SMS_Advertisement -Filter "AdvertisementName like '$AdvertName'"
#Set AdvertFlag (OVERRIDE_SERVICE_WINDOWS+DONOT_FALLBACK+NO_DISPLAY+ONSLOWNET)
$Advert.AdvertFlag = 101842944
#Set RemoteClientFlag (DOWNLOAD_FROM_LOCAL_DISPPOINT+DOWNLOAD_FROM_REMOTE_DISPPOINT+RERUN_ALWAYS)
$Advert.RemoteClientFlags = 2128
#Apply Advertisment modification
$Advert.put()
#Increment counting by 1
$Count ++
#Write message to user with total  advertisements
Write-Host "Processed Advertisements: $Count"
}

November 1st, 2014 2:35pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics