Get-VMInfo
Function Get-VMInfo { | |
<# | |
.SYNOPSIS | |
Gather general information about a group of VMs. | |
.DESCRIPTION | |
This function returns general information gathered from a set of one or more VMs. | |
Data returned - Folder, Name, PowerState, FullName, GuestOS, IP, NumCPU, MemoryGB, DiskGB, DiskUsedGB, DiskFreeGB, Notes | |
.PARAMETER VMs | |
VM object (Get-VM) | |
.EXAMPLE | |
Get-VM | Get-VMInfo | |
Returns info for all VMs | |
.EXAMPLE | |
Get-Folder Servers | Get-VM | Get-VMInfo | |
Returns info for all VMs located within the Servers folder | |
.NOTES | |
Author: Shawn Masterson | |
Created: Aug 2014 | |
Version: 1.0 | |
#> | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory=$True, | |
ValueFromPipeline=$True)] | |
[array]$VMs | |
) | |
Begin { | |
$output = @() | |
} | |
Process { | |
Foreach ($VM in $VMs) { | |
Write-Verbose "Processing $VM" | |
$tempvm = @{} | |
$tempvm.Folder = $VM.Folder | |
$tempvm.Name = $VM.Name | |
$tempvm.PowerState = $VM.PowerState | |
$tempvm.NumCPU = $VM.NumCPU | |
[int]$tempvm.MemoryGB = $VM.MemoryGB | |
$tempvm.DiskGB = [Math]::Round((($vm.HardDisks | Measure-Object -Property CapacityKB -Sum).Sum * 1KB / 1GB),2) | |
$tempvm.DiskFreeGB = If (![Math]::Round((($vm.Guest.Disks | Measure-Object -Property FreeSpace -Sum).Sum / 1GB),2)) ` | |
{"Tools Not Running\Unknown"} Else {[Math]::Round((($vm.Guest.Disks | Measure-Object -Property FreeSpace -Sum).Sum / 1GB),2)} | |
$tempvm.DiskUsedGB = If ($tempvm.DiskFreeGB -eq "Tools Not Running\Unknown") ` | |
{"Tools Not Running\Unknown"} Else {$tempvm.DiskGB - $tempvm.DiskFreeGB} | |
$tempvm.Notes = $VM.Notes | |
$tempvm.GuestOS = If (!$VM.Guest.OSFullName) {"Tools Not Running\Unknown"} Else {$VM.Guest.OSFullName} | |
$tempvm.IP = If (!$VM.Guest.IPAddress[0]) {"Tools Not Running\Unknown"} Else {$VM.Guest.IPAddress[0]} | |
$tempvm.FullName = If (!$VM.Guest.hostname) {"Tools Not Running\Unknown"} Else {$VM.Guest.hostname} | |
$temp = New-Object –TypeName PSObject –Prop $tempvm | |
$output += $temp | |
} | |
} | |
End { | |
$output | Select Folder, Name, PowerState, FullName, GuestOS, IP, NumCPU, MemoryGB, DiskGB, DiskUsedGB, DiskFreeGB, Notes | Sort Folder, Name | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment