Google Ads

Thursday, 31 December 2015 11:38

PowerShell script which collects virtual machine information from a VMM server 2012 R2

Rate this item
(0 votes)

This PowerShell script collects virtual machine information from a VMM server 2012 r2  and generates an HTML
report, displaying detailed configuration information for all virtual machines managed by the server: configuration
summary, network configuration and storage configuration.

<#
vmm-vm-report.ps1
Generates virtual machine configuration report

 

 

By Gleb Yourchenko
E-mail: This email address is being protected from spambots. You need JavaScript enabled to view it.

Version 2

Change history:
09.12.2014 Reorganized VM info loop;
fixed storage table generation

#>

param(
[String]$vmmServer = "localhost",
[String]$reportFile = "c:\scripts\vmm-config-report.htm"
)


Import-Module virtualmachinemanager


Get-SCVMMServer -ComputerName $vmmServer -SetAsDefault | Out-Null


$network_info = @()
$storage_info = @()


$VMs = Get-SCVirtualMachine -All
foreach( $VM in $VMs )
{
$info_name = $vm.Name
$host_info = "{0} ({1})" -F $vm.HostName.split(".")[0], $vm.VirtualizationPlatform
$size_info = "{0:N0} GB" -F ( $VM.TotalSize / (1024*1024*1024 ))

if ( $vm.IsPrimaryVM ) { $repl = "Primary VM" } elseif ( $vm.IsRecoveryVM ) { $repl = "Replica VM" } else { $repl = "No repl." }
if ( $vm.IsHighlyAvailable ) { $ha = "HA" } else { $ha = "No HA" }
$vm_info = "Gen. {0}, {1}, {2}" -F $vm.Generation, $repl, $ha

if ( $vm.DynamicMemoryEnabled )
{ $mem_info = "{0} MB (Dyn {1}-{2})" -F $vm.Memory, $vm.DynamicMemoryMinimumMB, $vm.DynamicMemoryMaximumMB }
else
{ $mem_info = "{0} MB (Static)" -F $vm.Memory }

$cpu_info = "{0} CPUs, {1}/{2}%" -F $vm.CPUCount, $vm.CPUReserve, $vm.CPUMax

$hdd_type = @()
$hdd_format = @()
$hdd_size = @()
$hdd_path = @()
$hdd_vol = @()
foreach( $hdd in $vm.VirtualHardDisks )
{
$hdd_format += $hdd.VHDFormatType
$hdd_type += $hdd.VHDType
$hdd_size += "{0:N0} of {1:N0}" -F ( $hdd.Size / 1073741824 ), ( $hdd.MaximumSize / 1073741824 )
$hdd_path += $hdd.Location
$hdd_vol += $hdd.HostVolume.Name
}

# network info
$ln_info = @()
$vmnet_info = @()
$ip_info = @()
$ip_str = ""
$vlan_info = @()

foreach( $nic in $vm.VirtualNetworkAdapters )
{
if ( $nic.IPv4Addresses.count ) { $ip_str = [String]::Join( " ", $nic.IPv4Addresses ) }
if ( $nic.IPv6Addresses.count ) { $ip_str += " " + [String]::Join( " ", $nic.IPv6Addresses ) }
$ip_info += $ip_str
if ( $nic.LogicalNetwork ) { $ln_info += $nic.LogicalNetwork.Name } else { $ln_info += "---" }
if ( $nic.VMNetwork ) { $vmnet_info += $nic.VMNetwork.Name } else { $vmnet_info += "---" }
if ( $nic.VLanEnabled ) { $vlan_info += ( "{0:N0}" -F $nic.VLanID ) } else { $vlan_info += "---" }
}
$ip_str = [String]::Join(" ", $ip_info )

Add-Member -InputObject $VM -MemberType NoteProperty -Name "Host Info" -value $host_info -Force
Add-Member -InputObject $VM -MemberType NoteProperty -Name "Size (GB)" -value $size_info -Force
Add-Member -InputObject $VM -MemberType NoteProperty -Name "VM Info" -value $vm_info -Force
Add-Member -InputObject $VM -MemberType NoteProperty -Name "VM Memory" -value $mem_info -Force
Add-Member -InputObject $VM -MemberType NoteProperty -Name "CPU, Res/Max" -value $cpu_info -Force
Add-Member -InputObject $VM -MemberType NoteProperty -Name "IP Info" -value $ip_info -Force
Add-Member -InputObject $VM -MemberType NoteProperty -Name "IP Adress(es)" -value $ip_str -Force
Add-Member -InputObject $VM -MemberType NoteProperty -Name "Logical Network" -value $ln_info -Force
Add-Member -InputObject $VM -MemberType NoteProperty -Name "VM Network" -value $vmnet_info -Force
Add-Member -InputObject $VM -MemberType NoteProperty -Name "VLAN" -value $vlan_info -Force

Add-Member -InputObject $VM -MemberType NoteProperty -Name "Disk Format" -value $hdd_format -Force
Add-Member -InputObject $VM -MemberType NoteProperty -Name "Type" -value $hdd_type -Force
Add-Member -InputObject $VM -MemberType NoteProperty -Name "Disk Size (GB)" -value $hdd_size -Force
Add-Member -InputObject $VM -MemberType NoteProperty -Name "Disk Path" -value $hdd_path -Force
Add-Member -InputObject $VM -MemberType NoteProperty -Name "Volume" -value $hdd_vol -Force

for( $i = 0; $i -lt $vm."VM Network".Count; $i+=1 )
{
$n = New-Object "System.object"
if ( $i -eq 0 ) { $e = $vm.Name } else { $e = "" }
Add-Member -InputObject $n -MemberType NoteProperty -Name "VM Name" -Value $e
Add-Member -InputObject $n -MemberType NoteProperty -Name "IP Adress(es)" -Value $vm."IP Info"[$i]
Add-Member -InputObject $n -MemberType NoteProperty -Name "Logical Network" -Value $vm."Logical Network"[$i]
Add-Member -InputObject $n -MemberType NoteProperty -Name "VM Network" -Value $vm."VM Network"[$i]
Add-Member -InputObject $n -MemberType NoteProperty -Name "VLAN" -Value $vm."VLAN"[$i]
$network_info += $n
}


for( $i = 0; $i -lt $vm."Type".Count; $i+=1 )
{
$n = New-Object "System.object"
if ( $i -eq 0 ) { $e = $vm.Name } else { $e = "" }
Add-Member -InputObject $n -MemberType NoteProperty -Name "VM Name" -Value $e
Add-Member -InputObject $n -MemberType NoteProperty -Name "Disk Format" -Value $vm.'Disk Format'[$i]
Add-Member -InputObject $n -MemberType NoteProperty -Name "Type" -Value $vm.'Type'[$i]
Add-Member -InputObject $n -MemberType NoteProperty -Name "Disk Size (GB)" -Value $vm.'Disk Size (GB)'[$i]
Add-Member -InputObject $n -MemberType NoteProperty -Name "Volume" -Value $vm.'Volume'[$i]
Add-Member -InputObject $n -MemberType NoteProperty -Name "Disk Path" -Value $vm.'Disk Path'[$i]
$storage_info += $n
}

}


$table_summary = $VMs | Sort-Object Name | ConvertTo-Html `
Name, "Size (GB)","CPU, Res/Max", "VM Memory", "VM Info", "Host Info", `
ComputerName, "IP Adress(es)" , OperatingSystem -Fragment


$table_network = $network_info | ConvertTo-Html `
"VM Name", "IP Adress(es)", "VM Network", "VLAN", "Logical Network" -Fragment


$table_storage = $storage_info | ConvertTo-Html -Fragment `
"VM Name", "Disk Format", "Type", "Disk Size (GB)", "Volume", "Disk Path"


$report = " <style>
TABLE{border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;white-space:nowrap;}
TH{border-width: 1px;padding: 4px;border-style: solid;border-color: black}
TD{border-width: 1px;padding: 2px 10px;border-style: solid;border-color: black}
</style> <body>
<H2>Virtual Machine Configuration Report for $vmmServer</H2>
<H3>VM Configuration Summary</H3>
$table_summary
<H3>VM Network Configuration</H3>
$table_network
<H3>VM Storage Configuration</H3>
$table_storage
</body>"


$report | Set-Content $reportFile -Force
Invoke-Expression $reportFile

Source: https://gallery.technet.microsoft.com/scriptcenter/VM-configuration-report-ae3b6ec6

 

Read 47772 times Last modified on Thursday, 31 December 2015 11:52
More in this category: « Office 365 port requirements