Advertisement
djdee

Untitled

Jan 31st, 2017
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'Technorati Tags: Hyper-V,VBScript
  2.  
  3. 'Checks to see if argument passed on command line, if not prompts for VM guest name
  4. If WScript.Arguments.Count <> 1 Then
  5.   Do
  6.      VMName = inputbox( "Please enter the name of the virtual guest ", "Input" )
  7.   Loop until VMName <> ""
  8.  
  9.  Else
  10.     VMName     = WScript.Arguments(0)
  11. End If
  12.  
  13. strVM = VMName
  14.  
  15. 'executes powershell to check for host value
  16. pscommand = " reg query '\\" & strVM & "\HKLM\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters' /v PhysicalHostNameFullyQualified "
  17. cmd = "powershell.exe -noprofile -command " & pscommand
  18. Set shell = CreateObject("WScript.Shell")
  19. Set executor = shell.Exec(cmd)
  20. executor.StdIn.Close
  21. strA = executor.StdOut.ReadAll
  22.  
  23. 'Displays host machine or error if nothing returned
  24. If strA = "" Then
  25.   'call MsgBox(strVM & " is not a virtual machine or is unreachable",vbOKOnly,"Error")
  26.  WScript.Echo strVM & " is not a virtual machine or is unreachable",vbOKOnly,"Error"
  27. WScript.Quit
  28. else
  29.  'WScript.Echo strA & strVM & " resides on:" & Replace(Replace(strA,"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters","")," PhysicalHostNameFullyQualified REG_SZ ","")
  30.   strHostname = Replace((Replace(strA, "PhysicalHostNameFullyQualified    REG_SZ","")),"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters","")
  31. '  WScript.Echo VMName & ":" & Replace((Replace(strA, "PhysicalHostNameFullyQualified    REG_SZ","")),"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters","")
  32. '  iCount = 0
  33.  
  34.   Do While InStr(1, strHostname, "  ")
  35.     strHostname = Replace(strHostname, "  ", " ")
  36. '    iCount = iCount+1
  37. '    Wscript.Echo iCount
  38.   Loop
  39.   strTrimHostname = Trim(Replace(strHostname, vbCrLf, ""))
  40.   WScript.Echo """" & VMName & """,""" & strTrimHostname & """"
  41. End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement