Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get WMI embedded array?

23 views
Skip to first unread message

Ant

unread,
Nov 5, 2009, 9:35:01 AM11/5/09
to

Hi folks,

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>------------------------------------------------------------------------------

Martin Zugec

unread,
Nov 5, 2009, 10:15:52 AM11/5/09
to
Hello there,

for advertisement object (let's say you call it $Advertisement), you
must call $Advertisement.psbase.Get() first.

Martin

Ant

unread,
Nov 6, 2009, 3:34:14 PM11/6/09
to
Martin Zugec...you rock! Your reply was the answer. I've pasted the final
script below for the benefit of others. Thanks!

$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
}

Martin Zugec

unread,
Nov 8, 2009, 8:48:23 AM11/8/09
to
Hi Ant,

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...

0 new messages