Skip to content

Instantly share code, notes, and snippets.

@kirkmawa
Last active June 8, 2017 12:51
Show Gist options
  • Save kirkmawa/4112429d38033f5385d188ece4f7fd24 to your computer and use it in GitHub Desktop.
Save kirkmawa/4112429d38033f5385d188ece4f7fd24 to your computer and use it in GitHub Desktop.
Remove-Module Hyper-V -ErrorAction SilentlyContinue
Import-Module Hyper-V -RequiredVersion 1.1
$VMFinalTable = @()
# Add VM host nodes to the following array
$VMHostNodes = @("E255HVC2H1","E255HVC2H2")
ForEach ($VMHostNode in $VMHostNodes) {
$VMList = Get-VM -ComputerName $VMHostNode | Where {$_.IsClustered -eq $true}
ForEach ($VMObj in $VMList) {
$VMObjTable = New-Object -TypeName PSObject
Add-Member -InputObject $VMObjTable -MemberType NoteProperty -Name "VMHostNode" -Value $VMObj.ComputerName
Add-Member -InputObject $VMObjTable -MemberType NoteProperty -Name "VMName" -Value $VMObj.Name
Add-Member -InputObject $VMObjTable -MemberType NoteProperty -Name "VMProcCount" -Value $VMObj.ProcessorCount
Add-Member -InputObject $VMObjTable -MemberType NoteProperty -Name "Memory" -Value ($VMObj.MemoryStartup / 1MB)
If ($VMObj.NetworkAdapters[0].DynamicMacAddressEnabled -eq $true) {
Add-Member -InputObject $VMObjTable -MemberType NoteProperty -Name "MacAddress" -Value "Dynamic"
} Else {
Add-Member -InputObject $VMObjTable -MemberType NoteProperty -Name "MacAddress" -Value $VMObj.NetworkAdapters[0].MacAddress
}
If ($VMObj.NetworkAdapters[0].VlanSetting.OperationMode -eq "Access") {
Add-Member -InputObject $VMObjTable -MemberType NoteProperty -Name "NetVlan" -Value $VMObj.NetworkAdapters[0].VlanSetting.AccessVlanId
} else {
Add-Member -InputObject $VMObjTable -MemberType NoteProperty -Name "NetVlan" -Value "Untagged"
}
ForEach ($VMIPAddress in $VMObj.NetworkAdapters[0].IPAddresses) {
If ($VMIPAddress -like "10.*") {
Add-Member -InputObject $VMObjTable -MemberType NoteProperty -Name "NetIPAddr" -Value $VMIPAddress
}
}
$VMFinalTable += $VMObjTable
}
}
$VMFinalTable | Format-Table
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment