none
Export all VMs and VHD from a Cluster Shared Volume RRS feed

  • Question

  • Hello Guys,

    I am trying to do a script to take all the VMs from a specific CSV (Cluster Shared Volme) and the VHD attached to them. 

    My script look like:

    Get-SCVirtualMachine -VMMServer VMMServerName -all | where{$_.location -like ‘C:\ClusterStorage\VolumeX’} | Select-Object Name,Location, @{N="Capacity(GB)";E={[math]::Round($_.TotalSize/ 1GB)}}


    The output is good but the only problem is with the VMs that have more the 1 VHD disk. I have VMs with multiple VHD disks on multimple CSV LUNs.

    EX: VM x has a disk on CSV1 and a disk on CSV2 and i need to get only the disk size from CSV1. In my script I get object TotalSize and because of that i get a sum of the 2 disks.

    I did some research on google and i found the command Get-VHD and i have modify my script like this:

    $VMs= Get-SCVirtualMachine -VMMServer VMMServerName -all | where{$_.location -like ‘C:\ClusterStorage\VolumeX’} 
    foreach ($VM in $VMs) {
    Get-VHD | Select-Object Name,Location, @{N="Capacity(GB)";E={[math]::Round($_.TotalSize/ 1GB)}}
    }

    But when i run it i get the message: Path[0]:

    What i am doing wrong?

    Thanks!


    Monday, July 22, 2019 2:18 PM

Answers

  • Hello,

    I managed to resolved. I need to put another array.

    The final version of the script looks like: 

    $report = @()
    $VMs = Get-SCVirtualMachine -VMMServer SCVMMName -all | where{$_.location -like ‘C:\ClusterStorage\Volume1X’}
    foreach ($VM in $VMs) {
    $VHDs = $VM | Get-SCVirtualDiskDrive
            foreach ($VHDconf in $VHDs) {
                        $data = New-Object PSObject -property @{
                        VHDCurrentSize = [Math]::Round($VHDconf.VirtualHardDisk.Size/1GB)
                        VMName=$VM.Name
                        Location=$VM.location
             
            }
            $report += $data
        }
    } 
    $report 
    
    Thanks all for the help

    Tuesday, July 23, 2019 9:06 AM

All replies

  • You'll find more PowerShell experts in dedicated forum over here.

    https://social.technet.microsoft.com/Forums/windowsserver/en-US/home?forum=winserverpowershell

     

     



    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

    Monday, July 22, 2019 2:24 PM
  • Get-VHD cannot be run without something specified for the -Path parameter. The portion "Get-VHD | Select-Object..." will always return that.

    Get-SCVirtualMachine does not emit any .VHDX data for you to plumb in that foreach.

    I don't have any systems with both VMM and Hyper-V cmdlets available. This works with just the Hyper-V cmdlets:

    Get-VMHardDiskDrive -vmname * | foreach {
        $Disk = Get-VHD -Path $_.Path
        @{VMName=$_.VMName;Location=$_.Path;'Capacity(GB)'=[math]::Round($Disk.Size/ 1GB)}
        }

    A similar thing should work with the VMM cmdlets. You could pipe Get-SCVirtualMachine to Get-SCVirtualHardDisk. But, Get-SCVirtualHardDisk does not emit the VM's name like Get-VMHardDiskDrive does, so you'd have to trap the VM name in an outer loop before creating the final emitted object.


    Eric Siron
    Altaro Hyper-V Blog
    I am an independent contributor, not an Altaro employee. I accept all responsibility for the content of my posts. You accept all responsibility for any actions that you take based on the content of my posts.

    Monday, July 22, 2019 3:37 PM
  • Hello Eric,

    Thanks for your help.

    I did what you told me, but I don't know if is correct. 

    My new script is: 

    $VMs = Get-SCVirtualMachine -VMMServer SCVMMVMName -all | where{$_.location -like ‘C:\ClusterStorage\VolumeX’}
    foreach ($VM in $VMs) {
    $VHDs = $VM | Get-SCVirtualDiskDrive
            foreach ($VHDconf in $VHDs) {
                        $data = New-Object PSObject -property @{
                        VHDCurrentSize = [Math]::Round($VHDconf.VirtualHardDisk.Size/1GB)
                        VMName=$VM.Name
                        Location=$VM.location
                        
                      
    }}}

    After i run the script and invoke $data i receive only one vm, with VMName, Location and Size in GB. So i think i am missing something, because the output is correct but jut for one VM not for all the VMs on the specific CSV. Can you take a look?

    Tanks




    Tuesday, July 23, 2019 7:26 AM
  • Hello,

    I managed to resolved. I need to put another array.

    The final version of the script looks like: 

    $report = @()
    $VMs = Get-SCVirtualMachine -VMMServer SCVMMName -all | where{$_.location -like ‘C:\ClusterStorage\Volume1X’}
    foreach ($VM in $VMs) {
    $VHDs = $VM | Get-SCVirtualDiskDrive
            foreach ($VHDconf in $VHDs) {
                        $data = New-Object PSObject -property @{
                        VHDCurrentSize = [Math]::Round($VHDconf.VirtualHardDisk.Size/1GB)
                        VMName=$VM.Name
                        Location=$VM.location
             
            }
            $report += $data
        }
    } 
    $report 
    
    Thanks all for the help

    Tuesday, July 23, 2019 9:06 AM