Last active
April 5, 2016 21:38
-
-
Save absolutejam/cea9b507433a3acee9a9d49e39dd5d83 to your computer and use it in GitHub Desktop.
Now FUNCTIONing (get it?!)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ClusteredVMs = Get-ClusterResource | ? ResourceType -eq 'Virtual Machine' | Select Name | |
$VMs = Get-VM -ComputerName node01,node02 | Select Name | |
Compare-Object $VMs $ClusteredVMs -IncludeEqual |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ErrorActionPreference = 'Continue' | |
<# | |
Name Memory (GB) Processor Count VM Root Path VHD VHDType Used (GB) Total (GB) Percent Free Virtual Switch IP VLAN | |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | |
BGS-APPS01 4 2 C:\ClusterStorage\VMs\BGS-APPS01 BGS-APPS01.VHDX Dynamic 50 100 50 B******** School 10.177.121.6 100 | |
BGS-APPS01 4 2 C:\ClusterStorage\VMs\BGS-APPS01 BGS-APPS01-Ddrive.VHDX Dynamic 50 100 50 B******** School 10.177.121.6 100 | |
#> | |
Function Quick-VMAudit { | |
[CmdletBinding()] | |
param( | |
[Parameter(ValueFromPipeline)] | |
[Microsoft.HyperV.PowerShell.VirtualMachine]$VMs | |
) | |
process { | |
ForEach ($VM in $VMs) { | |
# NICs | |
# This is in every entry | |
$NICSwitches = New-Object -TypeName System.Collections.ArrayList | |
$NICIPs = New-Object -TypeName System.Collections.ArrayList | |
$NICVLans = New-Object -TypeName System.Collections.ArrayList | |
ForEach ($NIC in $VM.NetworkAdapters) { | |
$NICSwitches.Add($NIC.SwitchName) | Out-Null | |
$NICIPs.Add($NIC.IPAddresses -Join(', ')) | Out-Null | |
$NICVLans.Add($NIC.VlanSetting.VLANList) | Out-Null | |
} | |
# VHDs | |
# Each entry for each VHD | |
$VHDs = Get-VHD $VM.HardDrives.Path -ComputerName $VM.ComputerName | Where VHDType -ne 'Differencing' | |
ForEach ($VHD in $VHDs) { | |
# Write-Host $VHD.Path | |
[PSCustomObject][ordered]@{ | |
'Name' = $VM.Name | |
'Memory (GB)' = ([math]::Round($VM.MemoryAssigned / 1Gb,1)) | |
'Processor count' = $VM.ProcessorCount | |
'VM Root Path' = $VM.Path | |
'VHD Path' = $VHD.Path | |
'VHD Type' = $VHD.VHDType | |
'VHD Used (GB)' = ([math]::Round($VHD.FileSize / 1Gb)) | |
'VHD Total Size (GB)' = ($VHD.Size / 1Gb) | |
'VHD Percent Free' = ([math]::Round(($VHD.FileSize / $VHD.Size) * 100)) | |
'Virtual Switch' = $NICSwitches -Join "`r`n" | |
'IP' = $NICIPs -Join "`r`n" | |
'VLAN' = $NICVLans -Join "`r`n" | |
} | |
} #ForEach ($VHD in $VHDs) | |
} #ForEach ($VM in $VMs) | |
} #process | |
} #function | |
Get-VM -ComputerName bgsclstr-node01,bgsclstr-node02 | Quick-VMAudit | ft |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment