我们有一个vCenter到VM映射到全局可访问的CSV的转储(UNC共享(,并让BGinfo在启动时通过VB脚本解析该CSV。
如果服务器名称匹配,则将IP地址分配给名为VCenter
的变量(否则,分配零长度字符串(:
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:BgInfovmdumps.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
在具有相同文件内容的不同服务器上输出:
示例VCenter未找到:cscript D:batSO67533523.vbs
My-Server: VCenter found at 10.10.10.10
示例VCenter发现:cscript D:batSO67533523.vbs
Xx-Server: VCenter not found