Quantcast
Channel: VMware Communities : Discussion List - Automation Tools
Viewing all articles
Browse latest Browse all 9071

Get all Vlan for the host and network info

$
0
0

Hello,

I need a script to get vlan information for each host with network information, I use this to get for each VM:

 

&{foreach($vm in (Get-VM)) {    $vm.ExtensionData.Guest.Net | select -Property @{N='VM';E={$vm.Name}},    @{N='Host';E={$vm.VMHost.Name}},    @{N='OS';E={$vm.Guest.OSFullName}},    @{N='Tools';E={$vm.ExtensionData.Guest.ToolsRunningStatus}},    @{N='NicType';E={[string]::Join(',',(Get-NetworkAdapter -Vm $vm | Select-Object -ExpandProperty Type))}},    @{N='VLAN';E={[string]::Join(',',(Get-NetworkAdapter -Vm $vm | Select-Object -ExpandProperty NetworkName))}},    @{N='IP';E={[string]::Join(',',($vm.Guest.IPAddress | Where {($_.Split(".")).length -eq 4}))}},    @{N='Gateway';E={[string]::Join(',',($vm.ExtensionData.Guest.IpStack.IpRouteConfig.IpRoute | %{if($_.Gateway.IpAddress){$_.Gateway.IpAddress}}))}},    @{N='Subnet Mask';E={                $dec = [Convert]::ToUInt32($(('1' * $_.IpConfig.IpAddress[0].PrefixLength).PadRight(32, '0')), 2)                $DottedIP = $( For ($i = 3; $i -gt -1; $i--) {                        $Remainder = $dec % [Math]::Pow(256, $i)                        (                        $dec - $Remainder) / [Math]::Pow(256, $i)                        $dec = $Remainder                    } )                [String]::Join('.', $DottedIP)             }},    @{N="DNS";E={[string]::Join(',',($vm.ExtensionData.Guest.IpStack.DnsConfig.IpAddress))}},    @{N='MAC';E={[string]::Join(',',$_.MacAddress)}}  }


} | Export-Csv C:\Users\gemela\Desktop\ESXI_Ip.csv

 

I need something similar to get info only for hosts.

 

Thanks


Viewing all articles
Browse latest Browse all 9071