For a customer I need to filter which Hosts (and VM's) have a connection with the DMZ VLAN's.
Problem is, the physical and virtual network VLAN's over multiple vCenter's aren't cosistent. So it can occur physical VLAN 24 is presented in the virtual network as VLAN 24 in one cluster and VLAN356 in an other.
My idea is to create a script that will search for observed IP-ranges (like 192.168.128.xxx) and show the VLAN Name, VLANID and VMHost information.
I'd like to get a csv file with this information, to be able to sort the outcome.
I really don't see if/how this can be done, and so I ask the help of the GURU's
Thanks in advance!
Arjan
Did you try it like this ?
$report = foreach($esx in Get-VMHost){ $vms = Get-VM -Location $esx
foreach($pg in (Get-VirtualPortGroup -VMHost $esx)){ $vms | where {$_.Guest.Nics | where {$_.NetworkName -eq $pg.Name}} | Select @{N="Host";E={$esx.Name}}, @{N="PG";E={$pg.Name}}, @{N="VLANid";E={$pg.VlanId}}, @{N="IP";E={[string]::Join(',',($_.Guest.Nics | where {$_.NetworkName -eq $pg.Name} | %{$_.IPAddress | %{$_}}))}}, @{N="VM";E={$_.Name}} } } $report | Export-Csv "C:\report.csv" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Could this help.
It will run through all portgroups, determine the VMs that have a connection over that portgroup and list the IP address(es) used by that VM over that portgroup.
foreach($esx in Get-VMHost){ $vms = Get-VM -Location $esx
foreach($pg in (Get-VirtualPortGroup -VMHost $esx)){ $vms | where {$_.Guest.Nics | where {$_.NetworkName -eq $pg.Name}} | Select @{N="Host";E={$esx.Name}}, @{N="PG";E={$pg.Name}}, @{N="VLANid";E={$pg.VlanId}}, @{N="IP";E={[string]::Join(',',($_.Guest.Nics | where {$_.NetworkName -eq $pg.Name} | %{$_.IPAddress | %{$_}}))}} } }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for sharing the script,
how to list the name of the VM here ?
I tried to do the $vms. but the properties & Method doesn't give me anything for displaying VM name at all ?
You can add one more calculated property on the Select-Object cmdlet.
Something like this
foreach($esx in Get-VMHost){ $vms = Get-VM -Location $esx
foreach($pg in (Get-VirtualPortGroup -VMHost $esx)){ $vms | where {$_.Guest.Nics | where {$_.NetworkName -eq $pg.Name}} | Select @{N="Host";E={$esx.Name}}, @{N="PG";E={$pg.Name}}, @{N="VLANid";E={$pg.VlanId}}, @{N="IP";E={[string]::Join(',',($_.Guest.Nics | where {$_.NetworkName -eq $pg.Name} | %{$_.IPAddress | %{$_}}))}}, @{N="VM";E={$_.Name}} } }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I really can't get it exported to a csv file 😞 tried Export-Csv on multiple locations, but it doesn't seem to work.
Please help? 😉
Greets, and a million thanks for every thing done already.
Did you try it like this ?
$report = foreach($esx in Get-VMHost){ $vms = Get-VM -Location $esx
foreach($pg in (Get-VirtualPortGroup -VMHost $esx)){ $vms | where {$_.Guest.Nics | where {$_.NetworkName -eq $pg.Name}} | Select @{N="Host";E={$esx.Name}}, @{N="PG";E={$pg.Name}}, @{N="VLANid";E={$pg.VlanId}}, @{N="IP";E={[string]::Join(',',($_.Guest.Nics | where {$_.NetworkName -eq $pg.Name} | %{$_.IPAddress | %{$_}}))}}, @{N="VM";E={$_.Name}} } } $report | Export-Csv "C:\report.csv" -NoTypeInformation -UseCulture
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc,
The Dutch government is very grateful to you :smileysilly: This really makes their live much easier.
Have a great weekend!