Script Center >
Scripting Forums
>
The Official Scripting Guys Forum!
>
How to get a *simple* reference of objects attributes
How to get a *simple* reference of objects attributes
- Hello All,
I'm not new to programming, in fact I've been doing it for as long as I can remember. But for the most part, I've been more of a traditional non OOP programmer. Unfortunately now most programming languages and scripts (vbscript in particular) are now Object oriented.
Now I'd be all for OOP if only I could find a clear, simple and complete reference for each object I want to access, and that including all inherited properties & methods. Up to now it's been an exercise in frustration as most of the time the scripts I find on the web are just about what I need, but missing that next little attribute I need. Case in point, I'm now looking to retrieve a computer FQDN from a computer object. On scriptcenter you can find the "Location" and "Description" properties, is that all the properties that can be found for a computer object? (For now my workaround will be to slap on the userdnsdomain environment variable of the current PC to the object's CN)
So in essence, I'm wondering what the Experts do when confronted to this situation, with what mindset do you tackle this? Does one need to ask the info on a forum list such as this and maybe get the information in a couple of days? Does one google or bing away for hours on end? Am I missing something? I would assume I'm not the only one with this particular situation (or maybe this has been answered before, I'd search but then again using what terms?)
If I'm not alone, I'd like to know about those confronted with the same dilema. IMHO, more admins would look into scripting if it just didn't take so much time getting the information you need. Hopefully a new thread could be pinned and titled "Newbie: where to get object information" or something similar. But again, I might be missing the point.
TIA for all the help provided
All Replies
It's not always easy to find references to what you need. Google or other search engines are often useful tools and experience helps a lot too.
If you have done something just remotely similar in the past you might have an idea of how to accomplish something new.
In the particular case you mention you could use the Win32_NetworkAdapterConfiguration WMI class.
It has the two attributes DNSHostName and DNSDomain that can be combined to find build the FQDN of the computer.
The user domain is not necessary the same as the computer domain so getting the dns name from the users domain could may work fine in some cases but be totally wrong in other.- Hi,If you are using Powershell, you could set the object you want to query and Pipe Get-Member to get all of its Properties and Methods.Like This Code:
1# $a = Get-WmiObject Win32_ComputerSystem 2# $a | Get-Member
And you Will Get This Output:Methods :JoinDomainOrWorkgroupRenameSetPowerStateUnjoinDomainOrWorkgroupProperties:AdminPasswordStatusAutomaticResetBootOptionAutomaticResetCapabilityBootOptionOnLimitBootOptionOnWatchDogBootROMSupportedBootupStateCaptionChassisBootupStateCreationClassNameCurrentTimeZoneDaylightInEffectDescriptionDomainDomainRoleEnableDaylightSavingsTimeFrontPanelResetStatusInfraredSupportedInitialLoadInfoInstallDateKeyboardPasswordStatusLastLoadInfo....If you are Using VBScript, You Can use Debug tools Like VBSEdit.In This Tool you can break the code on an object and see it's Properties.If not you can Use This Code to Query an Object in VBScriptI Hope This Answers your Question.strComputer = "." Set objWMIService=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _ strComputer & "\root\cimv2") Set colCompSystem = objWMIService.ExecQuery("Select * From Win32_ComputerSystem") For Each objCol In colCompSystem <span style="white-space:pre"> </span>WScript.Echo "Properties:" <span style="white-space:pre"> </span>For Each objProp In objCol.Properties_ <span style="white-space:pre"> </span>WScript.Echo objProp.Name <span style="white-space:pre"> </span>Next <span style="white-space:pre"> </span>WScript.Echo "Methods:" <span style="white-space:pre"> </span>For Each objMeth In objCol.Methods_ <span style="white-space:pre"> </span>WScript.Echo objMeth.Name <span style="white-space:pre"> </span>Next Next
Assaf Miron http://Assaf.Miron.googlepages.com- Edited byAssafM Wednesday, July 01, 2009 3:42 PMFormating
- I would use an object browsers first. There are many available, for example, one is included with Microsoft Script Editor (MSE7.exe), and it is capable of displaying members of selected COM objects. Microsoft Office VBA editor also has one. There is also a number of free standalone COM object browsers (like TLBViewer), although I admit I haven't used any of them in a while.
Microsoft Visual Studio also comes with an object browser capable of displaying both COM and .Net objects / classes (you can download free Visual Studio versions here). If you are interested in .Net, a tool called Lutz Roeder's Reflector is popular (I don't have much experience with it).
For browsing WMI classes I use WMI CIM Studio from WMI Administrative tools (you can download it it here) and Scriptomatic.
If I need more information on how to use a property / method I go to MSDN or Google. (I often search Google usenet archives).
urkec - Thank You all for the answers, that's a great start indeed, Will just hope my future ressearches will be easier! :)
Tkx

