Hello,
I am creating a menu driven function that will display all of VMs attached to a security tag. All of that works, the only issue I have is when the VMs display the security tag is not displaying.
function VM-Tag
{
cls
$v = Get-NsxSecurityTag | select name
$menu = for ($i = 0; $i -lt $v.Count; $i += 2)
{
$obj = [ordered]@{
Odd = "$($i+1). $($v[$i].Name)"
}
if ($v[$i + 1])
{
$obj.Add('Even', "$($i+2). $($v[$i+1].Name)") }
New-Object PSObject -Property $obj
}
$menu | Format-Table -HideTableHeaders
$choice = Read-Host -Prompt "Select Section (1..$($v.Count))"
$VMS = Get-NsxSecurityTagAssignment -SecurityTag (Get-NsxSecurityTag $v[$choice - 1].name)
cls
$VMS | FT
}
I am getting this for a display:
SecurityTag VirtualMachine
----------- --------------
securityTag G46PALATOWER004
securityTag G46PAL0011
securityTag G46PAL0012
securityTag G46PAL0013
securityTag G46PAL0014
I was hoping that the "security tag" would be my selection from the menu.
So:
SecurityTag VirtualMachine
----------- --------------
APP-TAG G46PALATOWER004
APP-TAG G46PAL0011
APP-TAG G46PAL0012
APP-TAG G46PAL0013
APP-TAG G46PAL0014
What am I missing?