I'm trying to create a new advertisement using Powershell. I've looked around and found a bunch of scripts that use WMI. Using Set-WMIInstance upon the SMS_Advertisement class. I can accomplish this!
My issue is that it seems there is another class SMS_AdvertisementInfo. When I use the SCCM 2007 Console and create a new advertisement, both classes are updated and have enties for the new advertisement.
I need help understanding the flow, There does not seem to be any documentation for the SMS_AdvertisementInfo class, and everyone just references adding instances to the SMS_Advertisement Class.
What am I doing wrong? The below code build the new advertisement from and existing one.
# Get all the advertisements for the specific package
$adv = Get-WmiObject -Namespace "root\SMS\$SMSSite" -Query "Select * from SMS_Advertisement WHERE PackageID = '$($pkg.PackageID)'" -ComputerName $SMSServer
# Get SMS Parts for creating the new Advertisement: CollectionID, PackageID, Program
$collectionID = (Get-WmiObject -Namespace "root\SMS\$SMSSite" -ComputerName $SMSServer -Query "Select * from SMS_Collection WHERE Name = '$AdvCollectionName'").CollectionID
$packageID = (Get-WmiObject -Namespace "root\SMS\$SMSSite" -ComputerName $SMSServer -Query "Select PackageID from SMS_Package WHERE Name = '$PkgName'").PackageID
$prg = Get-WmiObject -Namespace "root\SMS\$SMSSite" -ComputerName $SMSServer -Query "Select * from SMS_Program WHERE PackageID = '$($_.packageID)'"
$adv[2] | ForEach-Object {
# Build hashtable of arguments for the creation
$arguments = @{
AdvertFlags = $_.AdvertFlags;
AdvertisementName = "WIN7x64TEST - $($_.AdvertisementName)";
CollectionID = $collectionID;
PackageID = $_.packageID;
DeviceFlags = $_.DeviceFlags;
ProgramName = "WIN7x64TEST - $($_.ProgramName)";
RemoteClientFlags = $_.RemoteClientFlags;
SourceSite = $_.SourceSite;
TimeFlags = $_.TimeFlags
}
}
# Create the advertisement using the SMS_Advertisement WMI Class
Set-WmiInstance -class SMS_Advertisement -arguments $arguments -namespace "root\SMS\$SMSSite" -ComputerName $SMSServer