hello Luc,
can you check the following code i want to compare $pgs (which store all port gruopson vss) to $mgmt(which stores mangement port group on vss)
however there are unwanted strings in $mgmt i.e" key-vim.host.PortGroup-" can you suggest how to use remove or any easy method to get rid of this .
key-vim.host.PortGroup-VMNET-VLAN-410
key-vim.host.PortGroup-VM Network
key-vim.host.PortGroup-Management Network
foreach ($esxi in (get-vmhost -location $cluster))
{
#get-virtualswitch -vmhost $esxi -standard|select name,vmhost,@{N='portgroups';E={$_.extensiondata.Portgroup -join '|'}}
$vss=get-virtualswitch -vmhost $esxi -Standard
$pgs=$vss.ExtensionData.Portgroup
$pgs
$refpg =Get-VirtualPortGroup -Name "Management Network" -vmhost $esxi -standard
$mgmt=$refpg.name
$mgmt
if($pgs -cne "$mgmt")
{
write-host "there are portgrups other than managemnet network" -ForegroundColor DarkRed
}
else
{
write-host "only management network is configure on" $vss.name "on" $esxi.name
}
Try like this
Get-VirtualPortGroup -Name 'PG1' | Get-VM
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I would do this in this way.
foreach ($esxi in (Get-VMHost -location $cluster))
{
$vmkPg = Get-VMHostNetworkAdapter -VMHost $esxi -VMKernel | select -ExpandProperty PortGroupName
Get-VirtualSwitch -Standard -VMHost $esxi | Get-VirtualPortGroup |
where{$vmkpg -notcontains $_.Name} |
select @{N='VMHost';E={$esxi.Name}},@{N='Portgroup';E={$_.Name}}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
ThnaksLuc iam checking this but for the time bieng i compared with key not with names .
is there any property where in if i can check what vms are configured to standard port group.
Try like this
Get-VirtualPortGroup -Name 'PG1' | Get-VM
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
hello Luc ,
can yu please suggest what conditional operator shoud i use to compare two $pgs.name (containing name of all spg including virtual machine and vmkernel) and $mgmt.name.
following code does not give right output . can i use -eq for comparing two arrays .
foreach ($esxi in (get-vmhost -location $cluster))
{
$vss=get-virtualswitch -vmhost $esxi -Standard
$pgs=$vss|get-virtualportgroup
$mgmt =Get-VirtualPortGroup -Name "Management Network" -vmhost $esxi -standard
if($pgs.name -eq "$mgmt.name")
{
write-host "only management network is configured on" $vss.name "on" $esxi.name -ForegroundColor DarkGreen
}
else
{
write-host "there are portgrups other than managemnet network on" $vss.name "on" $esxi.name -ForegroundColor DarkRed
}
}
Try something like this
foreach ($esxi in (Get-VMHost -Location $cluster))
{
foreach($vss in (Get-VirtualSwitch -VMHost $esxi -Standard)){
$pgs = Get-VirtualPortGroup -VirtualSwitch $vss
$mgmt = Get-VirtualPortGroup -VirtualSwitch $vss -Name "Management Network" -VMHost $esxi -Standard
if((Compare-Object -ReferenceObject $pgs.name -DifferenceObject $mgmt.name -PassThru) -eq $null)
{
Write-Host "only management network is configured on" $vss.name "on" $esxi.name -ForegroundColor DarkGreen
}
else
{
Write-Host "there are portgrups other than managemnet network on" $vss.name "on" $esxi.name -ForegroundColor DarkRed
}
}
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc .