Author Topic: Array value  (Read 153 times)

Walls

  • Newbie
  • *
  • Posts: 11
Array value
« on: February 07, 2019, 10:07:42 am »
Hello all,

I have set up an IIS website and I am testing the script below. The goal is to collect some basic website information from IIS. Everything seems to work except for pulling the "site binding" information. I think the "site binding" value is in an array, but I am having a hard time extracting it out. Can someone tweak this to show me what I am doing wrong?

strComputer = "."
strClass = "Site"
objService = GetObject(StrCat("winmgmts:\\" , strComputer , "\root\webadministration" ))
objSites = objService.ExecQuery("SELECT * FROM Site")
title = StrCat( strClass , " Class Methods" )

ForEach objSite In objSites
    SiteName = objSite.Name
    SiteId = objSite.Id
    ArrSiteBindings = objSite.Bindings
    ArrDimsElements = ArrInfo ( ArrSiteBindings , 1 )
    For ElementIndex = 0 to ArrDimsElements
      If ElementIndex == ArrDimsElements then break
      SelectedBinding = ArrSiteBindings[ElementIndex]
      Message(ElementIndex ,SelectedBinding)
    Next
Next

Exit

JTaylor

  • Pundit
  • *****
  • Posts: 977
    • Data & Stuff Inc.
Re: Array value
« Reply #1 on: February 07, 2019, 10:21:41 am »
No expert but is that an array of Objects?  Do you need something like the following?


hostname = SelectedBinding.Hostname
ip              = SelectedBinding.IP
port          = SelectedBinding.Port

Jim

Walls

  • Newbie
  • *
  • Posts: 11
Re: Array value
« Reply #2 on: February 07, 2019, 10:49:30 am »
Yes! Pretty much what is in the attached screen shot. So I guess I am wrong about the array? :-X

JTaylor

  • Pundit
  • *****
  • Posts: 977
    • Data & Stuff Inc.
Re: Array value
« Reply #3 on: February 07, 2019, 12:36:27 pm »
Not necessarily.  If what you did worked apart from not getting the specific fields and you see a response on

Message(ElementIndex ,SelectedBinding)

then it is an array but the value in the array cell is an object so you need the

hostname = SelectedBinding.Hostname
ip              = SelectedBinding.IP
port          = SelectedBinding.Port

to retrieve the parts.

Again, no expert and I get errors on your script before the Array portion even comes into play so can't test that part easily.

Just trying to help until someone who knows what they are doing replies  ;)

Jim

Walls

  • Newbie
  • *
  • Posts: 11
Re: Array value
« Reply #4 on: February 07, 2019, 12:46:55 pm »
Thanks, I need all the help I can get. Let me play with it and I will repost.

td

  • Tech Support
  • *****
  • Posts: 2814
    • WinBatch
Re: Array value
« Reply #5 on: February 07, 2019, 01:06:10 pm »
WinBatch offers several simple ways to determine the type of a COM Automation supplied variable.  For example, you can simply run the script in the WinBatch Studio debugger.  The Watch window at the bottom of the WBS main frame will contain the variable names and their data types or you can call the ObjectTypeGet function with a variable as the parameter to obtain its data type.   
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

Walls

  • Newbie
  • *
  • Posts: 11
Re: Array value
« Reply #6 on: February 07, 2019, 02:20:25 pm »
Thanks for your help.

It tells me the type is string and the value is an ARRAY|VARIANT. Which what I suspected, but I am still struggling to extact the data. I will post back later. 

Walls

  • Newbie
  • *
  • Posts: 11
Re: Array value
« Reply #7 on: February 08, 2019, 07:41:55 am »
My post subject is probably not the best for my question, but at the time I didn't know what my issue was. Below is the code I got to work in my environment.  Thanks to all for the comments and help...

Code: Winbatch
objService = GetObject(StrCat("winmgmts:\\.\root\webadministration" ))
objSites = objService.ExecQuery("SELECT * FROM Site")


ForEach objSite In objSites
    WebSiteName = objSite.Name
    WebSiteId = objSite.Id
    ArrWebSiteBindings = objSite.Bindings
    type = ObjectTypeGet(ArrWebSiteBindings)
    If type !="EMPTY"
        WebSiteBindingsCnt = ArrInfo (ArrWebSiteBindings, 1)
        ForEach WebSiteBinding In ArrWebSiteBindings
                WebSiteProtocol = WebSiteBinding.Protocol
                WebSiteBindingInfo = WebSiteBinding.BindingInformation
                Display(1,StrCat("Site: ",WebSiteName),StrCat("Site ID: ",WebSiteId," Protocol: ",WebSiteProtocol, " Binding Information: ",WebSiteBindingInfo))

        Next
    End If
Next

Exit