locked
HV Cluster Hard Drive information RRS feed

  • Question

  • Hi,

    I'm new to Powershell, so please forgive me.

    I'm looking to find out which of the VMs in our HV Cluster have dynamically expanding hard drives.
    Is this possible through a PS script?
    I'd prefer not to open each VM individually and inspect each Virtual Hard Drive... there are hundreds of them!

    Thanks in advance,

    Peter

    Thursday, April 4, 2019 2:30 PM

All replies

  • Get-Command -Module Hyper-V
    ... should get you started ...

    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''

    Thursday, April 4, 2019 3:08 PM
  • Hi Peter,

    You can find these pretty easily by using your favorite Internet search engine, below you'll find a a few example scripts:

    Example 1

    Get all the Hyper-V virtual machines with dynamic disks:

    Get-VM –VMname * -Computername Host1, Host2 | Select-Object VMId | Get-VHD | Where-Object {$_.vhdType -eq "Dynamic"}

    Example 2

    Get all the Hyper-V virtual machines with dynamic disks and print out the results to a HTML file:

    Get-VM –VMname * -Computername Host1, Host2 | Select-Object VMId | Get-VHD | Where-Object {$_.vhdType -eq "Dynamic"} | ConvertTo-HTML > "C:\Temp\DynamicDisks.html"

    Example 3

    Get all the Hyper-V virtual machines with dynamic disks and print out the results to a text file:

    $Cluster = "HyperVCluster"
    $LogFile = "C:\Temp\VM_Dynamic_Disks.txt"
    $ClusterNodes = Get-ClusterNode -Cluster $Cluster
    
    $Results = ForEach ($ClusterNode in $ClusterNodes) {
        Invoke-Command -Computername $ClusterNode.Name {   
        ForEach ($VM in (Get-VM)){
        Get-VM -Name $VM.name | Select-Object VMID | Get-VHD | Where-Object {$_.vhdType -eq "Dynamic"} | fl @{Label="VirtualMachine";Expression={($VM.name)}},ComputerName, Path, VHDFormat, VHDType
        }
        }
        }
    $Results | Out-File -FilePath $LogFile


    Best regards,
    Leon


    Blog: https://thesystemcenterblog.com LinkedIn:

    Thursday, April 4, 2019 3:13 PM
  • This looks great!  Thanks Leon, I appreciate you getting back to me so quickly.
    Thursday, April 4, 2019 5:06 PM
  • Unfortunately, no log file is created.

    I've changed "HyperVCluster" to the name of my cluster.  No errors appear, but also no .txt file.

    When I try the HTML version, the HTML file gets created but it's blank.

    Any ideas?

    Thanks,
    Peter

    Thursday, April 4, 2019 5:47 PM
  • So you should check every single variable ... if it get's filled in.

    Run the code line by line and check the content of the created variables.

    You might start with learning the very basics of Powershell. That will help you to understand the help you'll get here and it'll help you to debug your own scripts.

    Edit: and BTW: when you crosspost in different forums at the same time you should place links to the other posts you did in the other forums to let the people willing to help you know that there  might be already more information or even already a solution

    https://powershell.org/forums/topic/cluster-vms-hard-drive-info/#post-149468


    Live long and prosper!

    (79,108,97,102|%{[char]$_})-join''



    • Edited by BOfH-666 Thursday, April 4, 2019 6:06 PM
    Thursday, April 4, 2019 6:03 PM
  • Thanks.

    Found the answer from Luke Orellana (I can't paste the link to his page).  Very easy to read.  Very appreciative of that, being a learner myself.  A nice step-by-step guide building up the script a section at a time and explaining what each section aims to achieve in terms of the information you aim to collect.  

    Understandably, it's only for the Node that I'm on, but I'll work to expand that to read from the Cluster:

    Get-VM –VMname * | Select-Object VMId | Get-VHD | ConvertTo-HTML –Property path,computername,vhdtype,
    @{label=’Size(GB)’;expression={$_.filesize/1gb –as [int]}} > “C:\SimpleVHDReport.htm"

    Guess it's time I started learning PS :) 

    Thanks, 
    Peter


    • Edited by hutchpm Friday, April 5, 2019 9:43 AM Code block
    Friday, April 5, 2019 9:42 AM
  • That’s great to hear! I believe the link is this one:

    https://www.altaro.com/hyper-v/gathering-vhd-info-get-vhd-powershell/


    Blog: https://thesystemcenterblog.com LinkedIn:

    Friday, April 5, 2019 9:46 AM