![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| 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. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | 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 Specs![]() |
| | #2 (permalink) |
| | 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 Specs![]() |
| | #3 (permalink) |
| | 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 Specs![]() |
![]() |
| 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 | |||