We have a dump of the vCenter to VM mappings to a CSV somewhere globally accessible (UNC share), and have BGinfo parse that CSV at launch via a VB script.
1 Answer
Assign IP address to variable named VCenter if server name match (otherwise, assign a zero-length string):
option explicit
On Error GoTo 0
'You should use a SPLIT command !
Dim fso,objTextFile, strComputer
' get local computer name
strComputer = CreateObject("Wscript.Network").ComputerName
set fso=CreateObject("Scripting.FileSystemObject")
dim arrStr, filepath
filepath = "C:\BgInfo\vmdumps.csv"
set objTextFile = fso.OpenTextFile(filepath)
Dim VCenter ''' assign a variable this value
VCenter = ""
Do while NOT objTextFile.AtEndOfstream
arrStr = split(objTextFile.ReadLine,",")
If UCase(Replace(arrStr(0),"""","")) = UCase(strComputer) Then
' wscript.echo strComputer & " (VCenter) :" & arrStr(1)
VCenter = Replace(arrStr(1),"""","")
Else
' wscript.echo arrStr(0) & " : " & arrStr(1)
End If
Loop
objTextFile.Close
If Not VCenter = "" Then
''' do something, e.g. demonstrate correct assignment
wscript.echo strComputer & ": VCenter found at " & VCenter
Else
''' do something else e.g. show that the variable is and empty string
wscript.echo strComputer & ": VCenter not found" & VCenter
End If
Output on different servers with the same file contents:
Example VCenter not found: cscript D:\bat\SO\67533523.vbs
My-Server: VCenter found at 10.10.10.10
Example VCenter found: cscript D:\bat\SO\67533523.vbs
Xx-Server: VCenter not found
strComputer = CreateObject("Wscript.Network").ComputerNameand inside thewhileloop e.g.If UCase(Replace(arrStr(0),"""","")) = UCase(strComputer) Then wscript.echo strComputer & " (VCenter) :" & arrStr(1)