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
}
}
Try something like this
$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
Try something like this
$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
Thanx.. Works perfect.Appreciate your time on this.