Get VM Drive Info?
-
Friday, October 10, 2008 8:38 PM
Need to get drive info for your VMs?
tony soper
All Replies
-
Friday, October 10, 2008 8:39 PM
option explicit
dim colArgs
dim vMachineName
dim tempStr
const PrintMode = 0 'mode 0 = file; 1 = screen
CONST path = "c:\temp\"'On Error Resume Next
set colArgs = wscript.Arguments
vMachineName = colArgs.item(0) ' get name of machine to scan
Print vMachineName, "Start Information for Virtual Machine = " & vMachineName, PrintMode
get_VM_info vMachineName
Get_Disks vMachineName
Print vMachineName, "Information garthering for Virtual Machine = " & vMachineName _
& ". Completed", PrintMode
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 4.1
'
' NAME: get_drive_info
'
' AUTHOR: richardCarpenter , Microsoft Corp
' DATE : 9/21/2008
'
' COMMENT: this function collects virtual machine hard drive information
'
'==========================================================================
private sub Get_Disks(vmachineName)
dim id
dim rtn
dim objvs
dim colvms
dim objvm
dim colArgs
DIM hdskConnections
dim objhdskconnection
dim objHardDisk
dim strfileSet objVS = CreateObject("VirtualServer.Application")
set colVMs = objVS.VirtualMachines
id = 0'need to query for virtual machine information
For Each objVM in colVMs
If lcase(objVM.Name) = lcase(vmachineName) then
set hdskConnections = objVM.HardDiskConnections
For Each objhdskconnection In hdskConnections
if objhdskconnection.BusType = 0 then
Print vMachineName,"Disk Type = IDE", PrintMode
elseif objhdskconnection.BusType = 1 then
Print vMachineName, "Disk Type = SCSI", PrintMode
end if
set objHardDisk = objhdskconnection.HardDisk
Print vMachineName, "Size on Host =" & objHardDisk.SizeOnHost, PrintMode
strFile = objHardDisk.File
Print vMachineName, "VM Disk File" & strfile, PrintMode
Next
end if
Next' release used resources
set objHardDisk = nothing
set objhdskconnection = nothing
set objVM = nothing
set objVS = nothingend sub
'==========================================================================
'
' VBScript Source File
'
' NAME: get_vm_info
'
' AUTHOR: richardCarpenter , Microsoft Corp
' DATE : 9/21/2008
'
' COMMENT: this function collects virtual machine hard drive information
'
'==========================================================================
private sub get_VM_info(vmachinename)dim objVS
dim colVMs
dim objVM
dim objGuestOSon error resume next
Set objVS = CreateObject("VirtualServer.Application")
set colVMs = objVS.VirtualMachines
For Each objVM in colVMS
if lcase(vMachineName) = lcase(objVM.Name) then
Print vMachineName, "Account name: " & objVM.accountname, PrintMode
Print vMachineName, "Account name and password: " & objVM.Accountnameandpassword, PrintMode
Print vMachineName, "Autostart at launch: " & objVM.Autostartatlaunch, PrintMode
Print vMachineName, "Autostart at launch delay: " & objVM.Autostartatlaunchdelay, PrintMode
Print vMachineName, "Config ID: " & objVM.ConfigID, PrintMode
Print vMachineName, "Display: " & objVM.Display, PrintMode
Print vMachineName, "File: " & objVM.File, PrintMode
Print vMachineName, "Floppy autodetect enabled: " & objVM.FloppyAutoDetectEnabled, PrintMode
Print vMachineName, "Guest OS: " & objVM.OSName, PrintMode
Print vMachineName, "Has MMX: " & objVM.HasMMX, PrintMode
Print vMachineName, "Has SSE: " & objVM.HasSSE, PrintMode
Print vMachineName, "Has SSE2: " & objVM.HasSSE2, PrintMode
Print vMachineName, "Memory: " & objVM.Memory, PrintMode
Print vMachineName, "Name: " & objVM.Name, PrintMode
Print vMachineName, "Notes: " & objVM.Notes, PrintMode
Print vMachineName, "Processor speed: " & objVM.ProcessorSpeed, PrintMode
Print vMachineName, "Run as defined account: " & objVM.RunAsDefinedAccount, PrintMode
Print vMachineName, "Saved state file path: " & objVM.SavedStateFilePath, PrintMode
Print vMachineName, "Shutdown action on quit: " & objVM.ShutdownActionOnQuit, PrintMode
Print vMachineName, "State: " & objVM.State, PrintMode
Print vMachineName, "Undoable: " & objVM.Undoable, PrintMode
Print vMachineName, "Undo action: " & objVM.UndoAction, PrintMode
Print vMachineName, "", PrintMode
end if
Nextset colVMs = nothing
set objVS = nothingend sub
'==========================================================================
'
' VBScript Source File
'
' NAME: Print
'
' AUTHOR: richardCarpenter , Microsoft Corp
' DATE : 9/24/2008
'
' INputs: Virtual Machine Name
' Output string
' Mode = Screen = 1
' File = 0
'
' COMMENT: this function prints either to screen/command line or file
'
'==========================================================================
Private sub Print(vMachineName, strOutput, bMode)
dim objFS, strOutFile
dim OutFile
dim OutputFileOutputFile = path & vMachineName & "_VM_Info.txt"
if bMode = 1 then 'we are printing to the screen
wscript.echo strOutput
elseif bMode = 0 then 'we are printing to a file
Set objFS = WScript.CreateObject("Scripting.FileSystemObject")
Set OutFile = objFS.OpenTExtFile(OutputFile , 8,true)
OutFile.writeline strOutput
OutFile.close
end if
end sub
tony soper- Marked As Answer by tonysoper_MSFT Friday, October 10, 2008 8:39 PM
-
Thursday, October 16, 2008 1:44 AMHow about for Hyper-V? Is there any way how to get the VM Drive info?
-
Wednesday, November 12, 2008 3:43 PMDid you ever get a reply or find out how to get vm drive info for Hyper-V ?
-
Friday, June 19, 2009 2:03 PMDo you mean how to use PowerShell to get the driveinfo?
Tony Soper -
Wednesday, August 26, 2009 12:41 PMTony this script is regarding finding out the virtual machine info for Microsoft vertual server.But i am interested in Hyper-V machine virtual machine.I want the same info that you specified in above script.Thanks,Prashant Mandawdhare
-
Wednesday, August 26, 2009 4:34 PM
Try the PowerShell Management Library for Hyper-V at: http://pshyperv.codeplex.com/
which includes, among many others:
Finding a VM
Get-VM, Choose-VM , Get-VMHost
tony soper- Proposed As Answer by prashant mandawdhare Tuesday, September 15, 2009 1:30 PM

