SCVMM Health Capacity Report

Are you in the phase of capacity planning for VM migration off your Hyper-V / System Center Virtual Machine Manager (SCVMM) environment? Do you need a capacity report of all running VMs and their allocated resources including CPU, memory, storage and network?

Check out the below PowerShell script which I’ve created to help produce the report you need.

Overview

All you need to do is save the below code snippet as a PS1 file and execute it using a PowerShell terminal, either from a jump server or SCVMM 2016 server with access to your virtual environment.

You will then be prompted to enter the IP or FQDN of your SCVMM 2016 environment.

The script will then generate a CSV report including:

  • Date timestamp.
  • All VMs in alphabetical order.
  • VM operating system.
  • VM status.
  • VM checkpoints (snapshots).
  • Allocated vCPU.
  • Allocated memory, static and dynamic.
  • Aggregate provisioned storage per VM.
  • Hyper-V host per VM.
  • Hyper-V guest integration service status.
  • Network information including VLAN, IPv4 address, IPv4 subnet and Default Gateway.

Prerequisites

  • PowerShell 4.0 or above.
  • SCVMM 2016.
  • Jump server (optional).

Script

<#
Author: Hugo S. Gungormez

Title: Get-SCVMMCapacityReport.ps1
Date: 09/07/2021
Version: 1.4.4
#>

$datestring = (Get-Date).ToString(“s”).Replace(“:”,”-“)
$VMMServer = Read-Host "Please enter your SCVMM server FQDN or IP: "
$filename = $datestring + "_" + $VMMServer + "_" + "VMM_Capacity_Planning_Report.csv"
$ProbeVMM = Get-SCVMMServer -ComputerName "$VMMServer"
$VMS = Get-scvirtualmachine | Sort-Object -Property Name

Write-Output "VM Name, Status, OS, Hyper-V Integration Services, Checkpoints, Storage, Memory, Dynamic Memory, vCPU, Hyper-V Host, VLAN, IP Address, Subnet, Default Gateway" | Out-File $filename
$Output = Foreach ($VM in $VMS)
{
    $VHDS = Get-SCVirtualHardDisk -VM $VM
    $storage = 0
    Foreach ($VHD in $VHDS)
    {
        $storage += $VHD.MaximumSize
    }
    $storage = $storage/1GB
    $storage = [math]::Round($storage)
    
    $status = $VM | Select-Object -ExpandProperty Status
    $vmOS = $VM | Select-Object -ExpandProperty OperatingSystem
    $hyperVIntegrationServices = $VM | Select-Object -ExpandProperty HasVMAdditions
    $checkpoints = $VM | Select-Object -ExpandProperty VMCheckpoints
    $memory = ($VM | Measure-Object -Property Memory -Sum).Sum -as [int]
    $dynamicMemory = ($VM | Measure-Object -Property DynamicMemoryMaximumMB -Sum).Sum -as [int]
    $vCPU = ($VM | Measure-Object -Property CPUCount -Sum).Sum -as [int]
    $vHostname = $VM | Select-Object -ExpandProperty HostName
    $vmVLAN = Get-SCVirtualNetworkAdapter -VM $VM | Select-Object -ExpandProperty VLanID
    $vmIP = Get-SCVirtualNetworkAdapter -VM $VM | Select-Object -ExpandProperty IPv4Addresses
    $vmSubnet = Get-SCVirtualNetworkAdapter -VM $VM | Select-Object -ExpandProperty IPv4Subnets
    $vmDefaultGateways = Get-SCVirtualNetworkAdapter -VM $VM | Select-Object -ExpandProperty DefaultIPGateways
    
    Write-Output "$VM, $status, $vmOS, $hyperVIntegrationServices, $checkpoints, $storage GB, $memory MB, $dynamicMemory MB, $vCPU vCPU, $vHostname, $vmVLAN, $vmIP, $vmSubnet, $vmDefaultGateways" | Out-File $filename -Append
} 

Report Example

Below exhibit is an example of a report generated from executing the script.

Conclusion

You can now save the output CSV report as a native Excel format file in XLSX, create a heading row and sort-filter to your requirements.

This report should contain all the information you need to carefully plan your VMs for migration OR provide you with an overview of your Hyper-V virtual infrastructure.

If you like this blog post, feel free to check out other related Microsoft cloud blogs at https://blog.feedspot.com/microsoft_azure_blogs/