通过 VB 脚本在启动时解析该 CSV [英] parse that CSV at launch via a VB script

查看:21
本文介绍了通过 VB 脚本在启动时解析该 CSV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们将 vCenter 到 VM 的映射转储到可全局访问(UNC 共享)某处的 CSV,并让 BGinfo 在启动时通过 VB 脚本解析该 CSV.

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.

推荐答案

如果服务器名称匹配,则为名为 VCenter 的变量分配 IP 地址(否则分配零长度字符串):

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:

示例VCenter 未找到:cscript D:\bat\SO\67533523.vbs

My-Server: VCenter found at 10.10.10.10

示例 VCenter found:cscript D:\bat\SO\67533523.vbs

Xx-Server: VCenter not found

这篇关于通过 VB 脚本在启动时解析该 CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆