Simple VM Inventory

Quicky

Another quicky to get all VMs from your hosts/cluster and display some basic information about them like CPU, memory, disk count and size.

  • I can get it using Windows Admin Center

  • or using PowerShell


    $HyperVHosts = @('Cluster1','Node1','Node2')
    $VMs = Get-VM ComputerName $HyperVHosts | ForEach-Object {
    Write-Host "Procesing VM {$($PSItem.VMName)}"
    Write-Host "Getting VM {$($PSItem.VMName)} disk information"
    $disks = Get-VHD VMId $PSItem.VMId ComputerName $PSItem.ComputerName
    $diskCount = $disks | Measure | Select-Object ExpandProperty Count
    $diskCurrentSize = $disks | Measure-Object Sum Property FileSize | Select-Object ExpandProperty Sum
    $diskMaximumSize = $disks | Measure-Object Sum Property Size | Select-Object ExpandProperty Sum
    [pscustomobject]@{
    Name = $PSItem.Name
    ComputerName = $PSItem.ComputerName
    MemoryMinimum = [System.Math]::Round($PSItem.MemoryMinimum /1GB,2)
    MemoryMaximum = [System.Math]::Round($PSItem.MemoryMaximum /1GB,2)
    MemoryAssigned = [System.Math]::Round($PSItem.MemoryAssigned /1GB,2)
    ProcessorCount = $PSItem.ProcessorCount
    DisksCount = $diskCount
    DiskCurrentSize = [System.Math]::Round($diskCurrentSize /1GB,2)
    DiskMaximumSize = [System.Math]::Round($diskMaximumSize /1GB,2)
    CreationTime = $PSItem.CreationTime
    }
    }
    $VMs | Format-Table Wrap

    view raw

    VMInventory.ps1

    hosted with ❤ by GitHub

    The output looks like this:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s