locked
Get VM Drive Info? RRS feed

  • Question

  • Need to get drive info for your VMs?


    tony soper
    Friday, October 10, 2008 8:38 PM

Answers

  • 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 strfile

    Set 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 = nothing

    end 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 objGuestOS

    on 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
    Next

    set colVMs = nothing
    set objVS = nothing

    end 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 OutputFile

       OutputFile = 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
    Friday, October 10, 2008 8:39 PM

All replies

  • 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 strfile

    Set 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 = nothing

    end 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 objGuestOS

    on 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
    Next

    set colVMs = nothing
    set objVS = nothing

    end 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 OutputFile

       OutputFile = 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
    Friday, October 10, 2008 8:39 PM
  • How about for Hyper-V? Is there any way how to get the VM Drive info?
    Thursday, October 16, 2008 1:44 AM
  • Did you ever get a reply or find out how to get vm drive info for Hyper-V ?
    Wednesday, November 12, 2008 3:43 PM
  • Do you mean how to use PowerShell to get the driveinfo?
    Tony Soper
    Friday, June 19, 2009 2:03 PM
  • Tony 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 12:41 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
    Wednesday, August 26, 2009 4:34 PM