Werbung: SecurityConsole.de verwaltet Ihre Computer mit Security Essentails aus der Cloud!
30 Tage kostenfrei testen und 20% Rabatt für Ihre Bestellung mit Promocode: WBF2685582
(Promocode gültig bis 31.12.2011)

Group:  English: Windows Server » microsoft.public.windows.server.scripting
Thread: store WMI property value in variable

HTVi
TV Discussion Newsgroups

store WMI property value in variable
Mecha77 5/3/2007 2:06:02 PM
Hi,
I made a WMI query to get the IP address of the local machine. I'd like to
know how to assign the address property to a string variable so I can
manipulate it.

Thanks
Re: store WMI property value in variable
Tom Lavedas <tglbatch[ at ]cox.net> 5/3/2007 4:22:50 PM
On May 3, 10:06 am, Mecha77 <Mech...[ at ]discussions.microsoft.com> wrote:
[Quoted Text]
> Hi,
> I made a WMI query to get the IP address of the local machine. I'd like to
> know how to assign the address property to a string variable so I can
> manipulate it.
>
> Thanks

I presume you have tried and are getting an error. Since you haven't
chosen to show the results of your attempt(s), one is left to guess at
the issue. A common problem is a failure to process the response
appropriately. In this case, the variable type of the IP Address
property of the collection provided by the query is a Variant array,
with just one item in it. This can be inferred from examples in the
Technet Script Center examples and/or determined using VBSs TypeName()
method. The latter is a technique I often use to troubleshoot a
script like this. In this case, it also came in handy to strip out
unwanted information from my simple general query ...

strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root
\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_NetworkAdapterConfiguration")
For Each objItem in colItems
if typename(objItem.IPAddress) <> "Null" then
if objItem.IPAddress(0) <> "0.0.0.0" Then
sIPAddress = objItem.IPAddress(0)
Wscript.Echo "IP Address: " & sIPAddress
end if
end if
Next

Note that this will return the LAST non-zero IP address. So, if there
is a prossibility for two or more network connections to be in place,
this simple approach will need to be modified.

TechNet Script Center Sample Scripts (URL all one line)
http://www.microsoft.com/downloads/details.aspx?FamilyID=b4cb2678-dafb-4e30-b2da-b8814fe2da5a

Tom Lavedas
============
http://members.cox.net/tglbatch/wsh/

Home | Search | Terms | Imprint Contact
Newsgroups Reader - provided by WiredBox.Net
Suche nach Orten, Städten, Postleitzahlen, Vorwahlen, Kfz-Kennzeichen