VMware Cloud Community
sandeep91116
Contributor
Contributor
Jump to solution

Report on VM's configured in port span

I would like to know if there is any script to retrieve all the vm's ( source)  which are configured in PORT SPAN ( ERSPAN)

From the below script i'm only getting info of port keys for the ERSPAN session i have configured. Can anyone let me know how to get vm info from port keys

$datacenter = 'DC'

$mirrorSessionName = 'Portspanning session name' 

$dvSwName = 'DVSwitch1'

$vmname = "VMName"

$dvSw = Get-VDSwitch -Name $dvSwName 

$vm = Get-VM -Name $vmname

$vmNic = $vm.ExtensionData.Config.Hardware.Device | where{$_.Backing -is [VMware.Vim.VirtualEthernetCardDistributedVirtualPortBackingInfo]} 

$spec = New-Object VMware.Vim.VMwareDVSConfigSpec 

foreach($mirrorSession in $dvSw.ExtensionData.Config.VspanSession)

    if($mirrorSession.Name -eq $mirrorSessionName)

    {

   # Write-Output $mirrorSessionName

     $vspan = New-Object VMware.Vim.VMwareDVSVspanConfigSpec 

     $mirrorSession.SourcePortReceived.PortKey

    

                             }

       }

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

Try something like this

$datacenter = 'DC'

$dvSwName = 'DVSwitch1'


$vds = Get-VDSwitch -Name $dvSwName

$ports = Get-VDPort -VDSwitch $vds

$vds.ExtensionData.Config.VspanSession |

where{$_.SessionType -eq [VMware.vim.VMwareDVSVspanSessionType]::encapsulatedRemoteMirrorSource} |

ForEach-Object -Process {

    $session = $_

    $session.SourcePortTransmitted.PortKey |

    ForEach-Object -Process {

        $stPort = $_

        $ports | where{$_.Key -eq $stPort} |

        ForEach-Object -Process {

            New-Object PSObject -Property @{

                Session = $session.Name

                Port = $stPort

                VM = $_.ConnectedEntity.Parent.Name

            }

        }

    }

    $session.SourcePortTransmitted.PortKey |

    ForEach-Object -Process {

        $stPort = $_

        $ports | where{$_.Key -eq $stPort} |

        ForEach-Object -Process {

            New-Object PSObject -Property @{

                Session = $session.Name

                Port = $stPort

                VM = $_.ConnectedEntity.Parent.Name

            }

        }

    }

} | Sort-Object -Property Session,Port -Unique


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

View solution in original post

0 Kudos
2 Replies
LucD
Leadership
Leadership
Jump to solution

Try something like this

$datacenter = 'DC'

$dvSwName = 'DVSwitch1'


$vds = Get-VDSwitch -Name $dvSwName

$ports = Get-VDPort -VDSwitch $vds

$vds.ExtensionData.Config.VspanSession |

where{$_.SessionType -eq [VMware.vim.VMwareDVSVspanSessionType]::encapsulatedRemoteMirrorSource} |

ForEach-Object -Process {

    $session = $_

    $session.SourcePortTransmitted.PortKey |

    ForEach-Object -Process {

        $stPort = $_

        $ports | where{$_.Key -eq $stPort} |

        ForEach-Object -Process {

            New-Object PSObject -Property @{

                Session = $session.Name

                Port = $stPort

                VM = $_.ConnectedEntity.Parent.Name

            }

        }

    }

    $session.SourcePortTransmitted.PortKey |

    ForEach-Object -Process {

        $stPort = $_

        $ports | where{$_.Key -eq $stPort} |

        ForEach-Object -Process {

            New-Object PSObject -Property @{

                Session = $session.Name

                Port = $stPort

                VM = $_.ConnectedEntity.Parent.Name

            }

        }

    }

} | Sort-Object -Property Session,Port -Unique


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

0 Kudos
sandeep91116
Contributor
Contributor
Jump to solution

Thanx.. Works perfect.Appreciate your time on this.

0 Kudos