PowerCLI

 View Only
Expand all | Collapse all

Need powershell script to get VMs disk information

  • 1.  Need powershell script to get VMs disk information

    Posted Feb 17, 2011 04:16 PM

    Dear all,

    I need powershell script to collect information from my VMs

    Output should look like

    VMnameDisk PathDisk capacityDisk Free spaceDevice LabelDatastoreDisk filenameDisk modeThin provisioned
    VM01C:\30GB15GBHard disk 1DT-R5-OS01VM01/VM01.vmdkpersistentFalse
    VM01D:\40GB10GBHard disk 2DT-R1-ST01VM01/VM02.vmdkpersistentTrue

    Can anyone help?

    Thanks,

    Evgeny



  • 2.  RE: Need powershell script to get VMs disk information

    Posted Feb 17, 2011 04:39 PM

    Have a look at Arnim's Miscellaneous script - Get-VMDiskMapping document.



  • 3.  RE: Need powershell script to get VMs disk information

    Posted Feb 17, 2011 05:01 PM

    Hi Luc,

    I looked at this scripts but it using connection to ESX hosts as well as to Guest OS which is some cases not workable for me.

    I tried to scripts from PowrGui "VMware Community PowerPack" and they giving me information i need but in two different places. I don't know how to combine them so I have one output.

    Scripit one "VM Guest Disk Space":

    if

    ($global:defaultviservers) {

    $AllVMs = Get-View -ViewType VirtualMachine | Where {-not $_.Config.Template}

    $SortedVMs = $AllVMs | Select *, @{N="NumDisks";E={@($_.Guest.Disk.Length)}} | Sort-Object -Descending NumDisks

    ForEach ($VM in $SortedVMs){

    $Details = New-object PSObject

    $Details | Add-Member -Name Name -Value $VM.name -Membertype NoteProperty

    $DiskNum = 0

    Foreach ($disk in $VM.Guest.Disk){

    $Details | Add-Member -Name "Disk$($DiskNum)path" -MemberType NoteProperty -Value $Disk.DiskPath

    $Details | Add-Member -Name "Disk$($DiskNum)Capacity(MB)" -MemberType NoteProperty -Value ([math]::Round($disk.Capacity/ 1MB))

    $Details | Add-Member -Name "Disk$($DiskNum)FreeSpace(MB)" -MemberType NoteProperty -Value ([math]::Round($disk.FreeSpace / 1MB))

    $DiskNum++

    }

    $Details.PSTypeNames.Clear()

    $Details.PSTypeNames.Add('Virtu-al.PowerPack.VMGuestDisks')

    $Details.PSTypeNames.Add('Virtu-al.PowerPack.VM')

    $Details

    }

    }

    Else

    {

    [

    System.Windows.Forms.MessageBox]::Show('You must connect to one or more hosts before you can use this node. Please click on the ''Managed Hosts'' node of the VMware PowerPack, connect to one or more of the servers you have configured there, and then try again.','Connection not established',[System.Windows.Forms.MessageBoxButtons]::OK,[System.Windows.Forms.MessageBoxIcon]::Information) | Out-Null

    }

    Script two "VM VMDK Information":

    # Thanks to ICT-FREAK.NL - http://ict-freak.nl/2009/10/11/powercli-virtual-machine-disk-vmdk-info-v2-analyze-data-with-excel/

    if

    ($global:defaultviservers) {

    foreach($vm in (get-view -ViewType VirtualMachine | Where-Object {-not $_.config.template})){

    foreach($dev in $vm.config.hardware.Device) {

    $Details = "" | Select-Object VMName, DeviceLabel, FileName, DiskMode, ThinProvisioned

    $Details.VMName = $vm.Name

    if ($dev.GetType().Name -eq "VirtualDisk") {

    $Details.DeviceLabel = $dev.DeviceInfo.Label

    $Details.FileName = $dev.Backing.FileName

    $Details.DiskMode = $dev.Backing.DiskMode

    if($dev.Backing.ThinProvisioned) {

    $Details.ThinProvisioned = "True"

    }

    else {

    $Details.ThinProvisioned = "False"

    }

    $Details.PSTypeNames.Clear()

    $Details.PSTypeNames.Add('Virtu-al.PowerPack.VMVMDKInfo')

    $Details.PSTypeNames.Add('Virtu-al.PowerPack.VM')

    $Details

    }

    }

    }

    }

    Else

    {

    [

    System.Windows.Forms.MessageBox]::Show('You must connect to one or more hosts before you can use this node. Please click on the ''Managed Hosts'' node of the VMware PowerPack, connect to one or more of the servers you have configured there, and then try again.','Connection not established',[System.Windows.Forms.MessageBoxButtons]::OK,[System.Windows.Forms.MessageBoxIcon]::Information) | Out-Null

    }

    thanks,

    Evgeny



  • 4.  RE: Need powershell script to get VMs disk information

    Posted Feb 17, 2011 05:10 PM

    Please check below website ... there are some useful scripts given

    http://www.virtu-al.net/2010/01/27/powercli-virtual-machine-disk-usage/



  • 5.  RE: Need powershell script to get VMs disk information

    Posted Feb 17, 2011 05:15 PM

    This link doesn't work.

    getting

    Forbidden



  • 6.  RE: Need powershell script to get VMs disk information

    Posted Feb 17, 2011 05:18 PM

    try this

    The script:

    Connect-VIServer MYVISERVER
    $MyCollection = @()
    $AllVMs = Get-View -ViewType VirtualMachine | Where {-not $_.Config.Template}
    $SortedVMs = $AllVMs | Select *, @{N="NumDisks";E={@($_.Guest.Disk.Length)}} | Sort-Object -Descending NumDisks
    ForEach ($VM in $SortedVMs){
     $Details = New-object PSObject
     $Details | Add-Member -Name Name -Value $VM.name -Membertype NoteProperty
     $DiskNum = 0
     Foreach ($disk in $VM.Guest.Disk){
     $Details | Add-Member -Name "Disk$($DiskNum)path" -MemberType NoteProperty -Value $Disk.DiskPath
     $Details | Add-Member -Name "Disk$($DiskNum)Capacity(MB)" -MemberType NoteProperty -Value ([math]::Round($disk.Capacity/ 1MB))
     $Details | Add-Member -Name "Disk$($DiskNum)FreeSpace(MB)" -MemberType NoteProperty -Value ([math]::Round($disk.FreeSpace / 1MB))
     $DiskNum++
     }
     $MyCollection += $Details
    }
    $MyCollection | Out-GridView
    # Export-Csv, ConvertTo-Html or ConvertTo-Xml can be used above instead of Out-Gridview

    The output is listed in a strange order due to an issue with this method of using PowerShell as mentioned here.

    Just a reminder that this information can also be viewed, filtered and exported using my VESI/PowerGUI PowerPack which you can download here. - Nearly 5000 downloads so far !



  • 7.  RE: Need powershell script to get VMs disk information

    Posted Feb 17, 2011 05:39 PM

    The reason Arnim's script needs to go into the guest OS is because the script needs to know which virtual disk (.vmdk) contains which guest OS partitions (C:\, D:\ ...).

    The script from Alan gives you the guest OS partitions but not the link to the .vmdk file.

    Btw the ISP where Alan's site is hosted is experiencing a problem.



  • 8.  RE: Need powershell script to get VMs disk information

    Posted Feb 18, 2011 09:14 AM

    yes .. his site is not opening...



  • 9.  RE: Need powershell script to get VMs disk information

    Posted Feb 18, 2011 09:29 AM

    please check this post .. http://www.google.co.in/url?q=http://communities.vmware.com/message/1423005

    you may get some additional information.



  • 10.  RE: Need powershell script to get VMs disk information

    Posted Feb 18, 2011 10:24 AM

    Luc,

    This is not going to work, as I have more than 100 vms and they are behind FW, so getting WMI to them is not possible. I try Veeam Reporter which running some scripts on the background only accessing VC and it can map drive letter to VMDK and show LUN path but this is very expensive to get licenses for all hosts I have.

    So there is a way to do it, but my scripting knowledge is zero.

    Thanks,

    Ev



  • 11.  RE: Need powershell script to get VMs disk information

    Broadcom Employee
    Posted Feb 18, 2011 11:00 AM

    My script retrieves WMI information from guests without accessing the VM network, and will also work for isolated VMs!

    Have a look at my post: http://www.van-lieshout.com/2010/02/powercli-match-vm-and-windows-harddisks-part-2/



  • 12.  RE: Need powershell script to get VMs disk information

    Posted Feb 18, 2011 12:31 PM

    Hi Armin,

    Thanks for your reply. But probably I want too much with doing less 

    Your script requires connection to ESX hosts, VM admin account and you have to specify individual vm name. In my case with over 100 VMs and no access to ESX host it will not work.

    For single VM it is easy to identify what and where but whole purpose of my request to do it on all VMs within vCenter.

    From two scripts above I attached earlier in the post, i believe it requesting information from two different sources and hence it can't be combined.

    Oh well, i will keep looking for a way out, but i you have any more suggestions that would be great.

    Thanks,

    Ev



  • 13.  RE: Need powershell script to get VMs disk information

    Posted Feb 21, 2023 01:29 PM

    DD_DeenDayal_0-1676985955476.png

     How can get VMware Virtual disk SCSI disk ... Location, Powershell fuction ? so we can compaire virtual scsi (0:1) refers to 160 and trager ID 1 similaerly 256 and target ID is 3 for SCSI ( 1:3)

     

     



  • 14.  RE: Need powershell script to get VMs disk information

    Posted Feb 21, 2023 03:28 PM

    Contrary to what some claim, there is no foolproof method to link those 2