Torgeir
Mon May 23 09:57:21 CDT 2005
Ravi wrote:
> "I gather that your text file is tab-delimited."
>
> Yes. The text file is tab-delimited
>
> "How many records are in the text file? How many fields?"
>
> Around 200 records and 3 fields each.
>
> "What are you really trying to do? One or multiple lookups? "
>
> No multiple lookups. Data in each of the 3 fields and 200 records will
> be completely unique.
>
> "Please describe your application in more detail."
>
> Here you go.
>
> Assume that this is my data file:
>
> wstr1s client-001 10.1.1.1
> wsed1s client-002 10.1.1.2
> ..................................................
> ...................................................
> edqr1s client-200 10.1.1.200
>
> Now, my WMI scripts within WinPE environment (check my previous post
> for more info) would capture systems service tag. Then the VBScript in
> the question should use the service tag captured to parse the above
> data file and retrieve client name and IP address into two different
> variables. For example, if the service tag is "wstr1s", CName should
> contain "client-001" & CIp should contain "10.1.1.1"
> At this point, i'll use some more scripts, which i have already
> written, to store CName as asset tag information in SMBIOS.
>
> I hope this explains the purpose. Please get back if you have any
> questions.
> How about changing this to XML format?? just a vague idea..!!!
Hi,
Create this XML file:
<?xml version="1.0" encoding="UTF-8"?>
<ServiceTagList>
<wstr1s>
<ClientName>client-001</ClientName>
<IPAddress>10.1.1.1</IPAddress>
</wstr1s>
<edqr1s>
<ClientName>client-200</ClientName>
<IPAddress>10.1.1.200</IPAddress>
</edqr1s>
</ServiceTagList>
Run this VBScript file (adjust the path/file name in the sFilePath
variable):
'--------------------8<----------------------
sFilePath = "C:\test\data.xml"
' capture systems service tag and assign it to the sServiceTag variable
' Note: Case sensitive to the same value in the XML file
sServiceTag = LCase("Wstr1s")
sXPath = "/ServiceTagList/" & sServiceTag
Set oXMLDoc = CreateObject("MSXML2.DOMDocument")
oXMLDoc.SetProperty "SelectionLanguage", "XPath"
oXMLDoc.Async = False
oXMLDoc.Load sFilePath
If (oXMLDoc.parseError.errorCode <> 0) Then
Set oErr = oXMLDoc.ParseError
WScript.Echo "Could not load file " & sFilePath _
& " , error: " & oErr.Reason
Else
On Error Resume Next
sClientName = oXMLDoc.SelectSingleNode(sXPath & "/ClientName").Text
sIPAddress = oXMLDoc.SelectSingleNode(sXPath & "/IPAddress").Text
If Err.Number <> 0 Then
WScript.Echo _
"Client name/IP address not found in XML file for service tag " _
& sServiceTag
Else
WScript.Echo "Client name: " & sClientName
WScript.Echo "IP address: " & sIPAddress
End If
End If
'--------------------8<----------------------
--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx