-1

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
  • Get strComputer = CreateObject("Wscript.Network").ComputerName and inside the while loop e.g. If UCase(Replace(arrStr(0),"""","")) = UCase(strComputer) Then wscript.echo strComputer & " (VCenter) :" & arrStr(1) Commented May 14, 2021 at 15:13

1 Answer 1

1

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
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.