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
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
Yes! Pretty much what is in the attached screen shot. So I guess I am wrong about the array? :-X
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
Thanks, I need all the help I can get. Let me play with it and I will repost.
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.
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.
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...
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