我正在尝试使用 Powershell 创建新广告。我四处寻找,发现一堆使用 WMI 的脚本。在短信广告同学们。我能做到!
我的问题是似乎还有另一个类SMS_广告信息。当我使用 SCCM 2007 控制台并创建新的广告时,两个类都会更新并包含新广告的实体。
我需要帮助来理解流程,似乎没有任何关于 SMS_AdvertisementInfo 类的文档,每个人都只是引用向 SMS_Advertisement 类添加实例。
我做错了什么?以下代码根据现有广告构建新广告。
# 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