Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'Technorati Tags: Hyper-V,VBScript
- 'Checks to see if argument passed on command line, if not prompts for VM guest name
- If WScript.Arguments.Count <> 1 Then
- Do
- VMName = inputbox( "Please enter the name of the virtual guest ", "Input" )
- Loop until VMName <> ""
- Else
- VMName = WScript.Arguments(0)
- End If
- strVM = VMName
- 'executes powershell to check for host value
- pscommand = " reg query '\\" & strVM & "\HKLM\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters' /v PhysicalHostNameFullyQualified "
- cmd = "powershell.exe -noprofile -command " & pscommand
- Set shell = CreateObject("WScript.Shell")
- Set executor = shell.Exec(cmd)
- executor.StdIn.Close
- strA = executor.StdOut.ReadAll
- 'Displays host machine or error if nothing returned
- If strA = "" Then
- 'call MsgBox(strVM & " is not a virtual machine or is unreachable",vbOKOnly,"Error")
- WScript.Echo strVM & " is not a virtual machine or is unreachable",vbOKOnly,"Error"
- WScript.Quit
- else
- 'WScript.Echo strA & strVM & " resides on:" & Replace(Replace(strA,"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters","")," PhysicalHostNameFullyQualified REG_SZ ","")
- strHostname = Replace((Replace(strA, "PhysicalHostNameFullyQualified REG_SZ","")),"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters","")
- ' WScript.Echo VMName & ":" & Replace((Replace(strA, "PhysicalHostNameFullyQualified REG_SZ","")),"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Virtual Machine\Guest\Parameters","")
- ' iCount = 0
- Do While InStr(1, strHostname, " ")
- strHostname = Replace(strHostname, " ", " ")
- ' iCount = iCount+1
- ' Wscript.Echo iCount
- Loop
- strTrimHostname = Trim(Replace(strHostname, vbCrLf, ""))
- WScript.Echo """" & VMName & """,""" & strTrimHostname & """"
- End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement