Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - How to get WMI embedded array?

Reply
 
Old 4 Weeks Ago   #1 (permalink)
Ant


 
 

How to get WMI embedded array?

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

My System SpecsSystem Spec
Old 4 Weeks Ago   #2 (permalink)
Martin Zugec


 
 

Re: How to get WMI embedded array?

Hello there,

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

Martin
My System SpecsSystem Spec
Old 3 Weeks Ago   #3 (permalink)
Ant


 
 

RE: How to get WMI embedded array?

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" wrote:
Quote:

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

"Ant" wrote:
Quote:

> 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
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Fast copy method of sub array (=array range) possible? VB Script
How to create array without quotes? $array = (a,b,c) PowerShell
Array indexing: Want to say "Item #2 through the rest of the array." PowerShell
Stupid Array Tricks: Initializing an Array to a Certain Size PowerShell
how to assign values to array and how to create array via variable PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46