Automating the "run" of the downloaded advert

Apr 6, 2011 at 3:59 PM

Hi,


I’d really appreciate some help. I’m trying to find the correct method to “Run” and advertisement once it’s download (rather than wait for countdown we’ve configured of 5 minutes.

I’ve added my code below which looks for all outstanding adverts, executes and then wait around for the running advert to finish.

[void][System.Reflection.Assembly]::LoadFile("c:\Program Files\SCCM Tools\SCCM Client Center\smsclictr.automation.dll")
$SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("localhost")
$SMSClient.RequestMachinePolicy()
$SMSAdverts = @($SMSClient.SoftwareDistribution.Advertisements)
$SMSAdverts | ft PKG_Name,PKG_PackageID,ADV_ADF_Published,PRG_MaxDuration,PRG_Category
$SMSAdvertsNotInstalled =  $SMSAdverts | Where-Object {$_.ADV_ADF_Published -eq $False}
$SMSAdvertsNotInstalled | ft PKG_Name,PKG_PackageID,ADV_ADF_Published,PRG_MaxDuration,PRG_Category

ForEach ($SMSAdvertisement in $SMSAdvertsNotInstalled){
    $SMSClient.SoftwareDistribution.RerunAdv($SMSAdvertisement.ADV_AdvertisementID,$SMSAdvertisement.PKG_PackageID,$SMSAdvertisement.PRG_ProgramID)
    #We need to wait until the advert has finished
    Do {
        Write-Host "Waiting for " $SMSAdvertisement.PKG_Name $SMSAdvertisement.ADV_AdvertisementID,$SMSAdvertisement.PKG_PackageID,$SMSAdvertisement.PRG_ProgramID "to finish"
	#Ok so this is were I'm stuck ... I'd like to add some code to "Run" the advert and not wait for the configured run time .. as a user I can click run but I'm struggling to find the methord - Help!
        Start-Sleep 1
        }
    Until (!($SMSClient.SoftwareDistribution.RunningAdv.AdvertID))
        
    Write-Host "Finished waiting for " $SMSAdvertisement.PKG_Name $SMSAdvertisement.ADV_AdvertisementID,$SMSAdvertisement.PKG_PackageID,$SMSAdvertisement.PRG_ProgramID "to finish"
}

I've looked at the Class diagram but I'm really struglling with the last "little" step of automating the "run" of the downloaded advert.

Any and all help much appreicated.

Kind Regards,

John  

Coordinator
Apr 12, 2011 at 7:09 PM

If you want to hide the countdown, you have to tweak the advertisement before triggering... Set the Advertisement Property "PRG_PRF_RunNotification" to "false" and the countdown should not appear... (i've not tested it, it's only theory) :-)

 

Regards

Roger

Apr 27, 2011 at 3:42 PM

Hi,

Sorry for the delay in answering back. It tried changing PRG_PRF_RunNotification, ADV_RunNotificationCountdownDuration and ADV_ADF_RunNotification but still get the ballon "Program Countdown Status".

I'll continue to scratch my head.

Coordinator
May 2, 2011 at 7:21 AM

I did some additional tests, but I can definetly disable the balloon by setting PRG_PRF_RunNotification = false. You have to store (Put) the changes on the Advertisement... and the changes will be reverted with the next policy cleanup cycle.

Do you have a sample code where you change the PRG_PRF_RunNotification Flag ?

 

Regards

Roger

May 3, 2011 at 7:58 AM

Hi,

Thanks for testing, I really appreciate it. I've added the code below "$SMSAdvertisement.PRG_PRF_RunNotification = $False" which sets it to false. When I look at the members of the advertisment object I get PRG_PRF_RunNotification                       Property     System.Boolean PRG_PRF_RunNotification {get;set;} ... is there something else I'm missing which sets/rights the object back? Really sorry if this is a newbie type mistake.

[void][System.Reflection.Assembly]::LoadFile("c:\System\SMSCliCtr\Program Files\SCCM Tools\SCCM Client Center\smsclictr.automation.dll")
$SMSClient = New-Object -TypeName smsclictr.automation.SMSClient("localhost")
$SMSClient.RequestMachinePolicy()
$SMSAdverts = @($SMSClient.SoftwareDistribution.Advertisements)
$SMSAdverts | ft PKG_Name,PKG_PackageID,ADV_ADF_Published,PRG_MaxDuration,PRG_Category
$SMSAdvertsNotInstalled =  $SMSAdverts | Where-Object {$_.ADV_ADF_Published -eq $False}
$SMSAdvertsNotInstalled | ft PKG_Name,PKG_PackageID,ADV_ADF_Published,PRG_MaxDuration,PRG_Category

ForEach ($SMSAdvertisement in $SMSAdvertsNotInstalled){
    $SMSAdvertisement.PRG_PRF_RunNotification = $False
    # The line above appears to set the correct value on the advert but it doesn't take effect when the advert is run.
    $SMSClient.SoftwareDistribution.RerunAdv($SMSAdvertisement.ADV_AdvertisementID,$SMSAdvertisement.PKG_PackageID,$SMSAdvertisement.PRG_ProgramID)
    #We need to wait until the advert has finished
    Do {
        Write-Host "Waiting for " $SMSAdvertisement.PKG_Name $SMSAdvertisement.ADV_AdvertisementID,$SMSAdvertisement.PKG_PackageID,$SMSAdvertisement.PRG_ProgramID "to finish"
        Start-Sleep 1
        }
    Until (!($SMSClient.SoftwareDistribution.RunningAdv.AdvertID))
       
    Write-Host "Finished waiting for " $SMSAdvertisement.PKG_Name $SMSAdvertisement.ADV_AdvertisementID,$SMSAdvertisement.PKG_PackageID,$SMSAdvertisement.PRG_ProgramID "to finish"
}

Coordinator
May 3, 2011 at 9:01 AM

"$SMSAdvertisement.PRG_PRF_RunNotification = $False" does only update the cached Object in Memory. You have to store the changed Advertisement back to WMI by using a "$SMSAdvertisement.Put()" before you call the $SMSClient.SoftwareDistribution.RerunAdv method...,

May 3, 2011 at 9:05 AM

Excellent.

Thank you ever so much. I think I need to get a book on com objects! ;o)

Your a star and have made my week, thanks again.

J