I'm trying to convert the below VBScript to PowerShell. I always come up
with a null array when trying to enumerate the AssignedSchedules with
PowerShell but with VBScript it works. I would like to run this script on a
SMS/SCCM site server to retrieve the assigned schedules for a specific
advertisement. Any help would be appreciated!
Thanks,
Ant
<Start
Script>-----------------------------------------------------------------------------
Dim objAdv, objToken
'Command line Arguments
argAdvID = WScript.Arguments(0)
'Connect to site server
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSWbemServices = objSWbemLocator.ConnectServer("<server_name>",
"root\sms\site_<site_name>")
'Get advertisement instance
Set objAdv = objSWbemServices.Get("SMS_Advertisement.AdvertisementID='" &
argAdvID & "'")
'Echo advertisement properties
WScript.Echo "AdvertisementID = " & objAdv.AdvertisementID
WScript.Echo "AdvertisementName = " & objAdv.AdvertisementName
WScript.Echo "CollectionID = " & objAdv.CollectionID
'Enum advertisement properties
set AdvProperties = objAdv.Properties_
Set colAssignedSchedules = AdvProperties.Item("AssignedSchedule")
intsize = 0
'Loop through and display each assigned schedule
For i = 0 to ubound(colAssignedSchedules)
Set objToken = colAssignedSchedules(i)
WScript.Echo colAssignedSchedules.Name & ": " & objToken.StartTime
Next
<End
Script>------------------------------------------------------------------------------
for advertisement object (let's say you call it $Advertisement), you
must call $Advertisement.psbase.Get() first.
Martin
$Computer = "<server_name>"
$Namespace = "root\sms\site_<Site_Name>"
$Class = "SMS_Advertisement"
$SCCMAdvertisement = Get-WmiObject -class $Class -computer `
$Computer -namespace $Namespace | where {$_.AdvertisementID `
-eq "<AdID>"}
$SCCMAdvertisement.psbase.Get() #This line of code was the answer!
$AdvProperties = $SCCMAdvertisement.AssignedSchedule
foreach ($Adv in $AdvProperties)
{
Write-Host $Adv.StartTime
}
glad I could help. You can also get rid of <Site_Name>:
http://martinzugec.blogspot.com/2009/11/how-to-get-sccm-site-code-using.html
Martin
"Ant" <A...@discussions.microsoft.com> wrote in message
news:D42FF743-5AEE-4676...@microsoft.com...