VMware Cloud Community
RajuVCP
Hot Shot
Hot Shot

Script to know how many VLAN access my ESXi have

Hi All,

Not sure if any one came across such requirement. I am looking for a script which can show my esxi connected to how many active VLANs.

Based on the NIC i should get the information on that NIC connected to how many active VLANs.

Thanks a ton in advance.

Raju Gunnal VCP 4, VCP 5, VTSP 4, VTSP 5, ITIL V3 http://www.techtosolution.com
Reply
0 Kudos
12 Replies
LucD
Leadership
Leadership

How would you determine if a VLAN is "active" ?

If there is a powered on VM connected to the portgroup ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
RajuVCP
Hot Shot
Hot Shot

"Active" i mean to say if the VMs in that VLAN able to pick the IPs or not.

example _ if i have 5 VLAN in my cluster VLAN 1, 2, 3, 4 & 5, out of which only 3 vlans working vlan 1,2,3.

In such case how to see if how many vlan present any which all vlans can able to give  ips to VMs.

Raju Gunnal VCP 4, VCP 5, VTSP 4, VTSP 5, ITIL V3 http://www.techtosolution.com
Reply
0 Kudos
LucD
Leadership
Leadership

Do all VMs have VMware Tools installed ?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
RajuVCP
Hot Shot
Hot Shot

Yes all the VMs have VMtools installed, but i was willing to get the connected VLAN details from host NIC. Not from VM.

Raju Gunnal VCP 4, VCP 5, VTSP 4, VTSP 5, ITIL V3 http://www.techtosolution.com
Reply
0 Kudos
RajuVCP
Hot Shot
Hot Shot

Just found a script on vmware blog, the script something should be like.

Get-VMHost host1.abc.com | Get-VMHostNetworkAdapter | where { $_.Name -eq "vmnic1" } | Get-ObservedIPRange

But am  getting error as Get-ObservedIPRange invalid command.

Raju Gunnal VCP 4, VCP 5, VTSP 4, VTSP 5, ITIL V3 http://www.techtosolution.com
Reply
0 Kudos
LittleNickey
Enthusiast
Enthusiast

Looks like Get-ObservedIPRange isn't part of the PowerCLI modules but a function someone has written.

Try adding the function first. Don't know what blog you were reading, but unless you provide the link I can only guess it is this function: http://poshcode.org/1653

-- Oskar
Reply
0 Kudos
RajuVCP
Hot Shot
Hot Shot

Here is the link

How to find out what VLANs your ESX hosts can really see. - VMware PowerCLI Blog - VMware Blogs

Raju Gunnal VCP 4, VCP 5, VTSP 4, VTSP 5, ITIL V3 http://www.techtosolution.com
Reply
0 Kudos
LittleNickey
Enthusiast
Enthusiast

Reading the comments of that blog, it looks like "Frank" is using the same function as I linked.

You need to add the function before running that command.

-- Oskar
Reply
0 Kudos
LittleNickey
Enthusiast
Enthusiast

Or if you just want to know the IP ranges you can use alanrenouf‌ script: http://www.virtu-al.net/2008/12/08/observed-ip-ranges/

This does not show the VLAN ID's however.

-- Oskar
Reply
0 Kudos
RajuVCP
Hot Shot
Hot Shot

That's usefull will try it. Smiley Happy

Raju Gunnal VCP 4, VCP 5, VTSP 4, VTSP 5, ITIL V3 http://www.techtosolution.com
Reply
0 Kudos
RajuVCP
Hot Shot
Hot Shot

I was trying to run the command but getting error Get-ObservedIPRange


Suggestion [3,General]: The command Get-ObservedIPRange was not found, but does

exist in the current location. Windows PowerShell does not load commands from th

e current location by default. If you trust this command, instead type ".\Get-Ob

servedIPRange". See "get-help about_Command_Precedence" for more details.

PowerCLI D:\MY DATA\PROJECTS\VLAN>

how to i run the below given command

Get-VMHost iphvsvv028h01.wellsfargo.com | Get-VMHostNetworkAdapter | Where { $_.Name -eq "vmnic1" } | Get-ObservedIPRange​

Raju Gunnal VCP 4, VCP 5, VTSP 4, VTSP 5, ITIL V3 http://www.techtosolution.com
Reply
0 Kudos
ITSavant
Contributor
Contributor

Function Get-ObservedIPRanges {

  [CmdletBinding()]

  param(

  [Parameter(Mandatory=$true,ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$True,HelpMessage=”Enter VMHost Name”)]

  [Object[]]$vmhostName

  )

  $vmhosts = Get-VMHost $vmhostName | Get-View

  foreach ($vmhost in $vmhosts){

  $networkSystem = Get-view $vmhost.ConfigManager.NetworkSystem

  Write-Host $vmhost.Name -foregroundcolor yellow

  foreach($netSys in $networkSystem){

  foreach($pnic in $netSys.NetworkConfig.Pnic){

  $subnets = $netSys.QueryNetworkHint($pnic.Device)

  foreach($pnicHint in $subnets){

  Write-Host $pnicHint.Device

  foreach($pnicIpHint in $pnicHint.Subnet){

  Write-Host "`t" $pnicIpHint.IpSubnet "`tVLAN `("$pnicIpHint.VlanId"`)"

  }

  }

  }

  }

  }

}

Get-ObservedIPRanges MyServerName

Reply
0 Kudos