通过 VB 脚本在启动时解析该 CSV
parse that CSV at launch via a VB script
我们将 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:\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
在不同服务器上输出相同文件内容:
示例 VCenter 未找到:cscript D:\bat\SO533523.vbs
My-Server: VCenter found at 10.10.10.10
示例 VCenter 找到:cscript D:\bat\SO533523.vbs
Xx-Server: VCenter not found
我们将 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:\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
在不同服务器上输出相同文件内容:
示例 VCenter 未找到:cscript D:\bat\SO533523.vbs
My-Server: VCenter found at 10.10.10.10
示例 VCenter 找到:cscript D:\bat\SO533523.vbs
Xx-Server: VCenter not found