Automation

 View Only
  • 1.  NSX - Remove Single NSX Security TAG from Single VM using PowerCLI

    Posted Apr 13, 2020 07:18 PM

    PowerNSX has Remove-NsxSecurityTagAssignment but that removes all tags. I want to remove a single NSX Security TAG from a Single VM.

    #This line will remove all TAGS from VM

    Get-VM VM01 | Get-NsxSecurityTagAssignment | Remove-NsxSecurityTagAssignment

    #This line will display only one tag

    Get-VM VM01 | Get-NsxSecuritytagassignment | select-object @{Name="SecurityTag"; expression = {$_.securitytag.name}}, VirtualMachine | Where-Object {$_.SecurityTag -like '*SecurityTag01*'}

    #This line will display only one tag but remove doesn’t work.

    Get-VM TempWin2012R2 | Get-NsxSecuritytagassignment | select-object @{Name="SecurityTag"; expression = {$_.securitytag.name}}, VirtualMachine | Where-Object {$_.SecurityTag -like '*SecurityTag01*'} | Remove-NsxSecurityTagAssignment

    Any help would be appreciated.



  • 2.  RE: NSX - Remove Single NSX Security TAG from Single VM using PowerCLI
    Best Answer

    Posted Apr 13, 2020 07:31 PM

    That is due to the Select in your pipeline.

    The Select cmdlet produces another object that Remove-NsxSecurityTagAssignment can't handle.

    Try like this

    Get-VM VM01 | Get-NsxSecurityTagAssignment |

    Where-Object {$_.Name -like '*SecurityTag01*'} |

    Remove-NsxSecurityTagAssignment



  • 3.  RE: NSX - Remove Single NSX Security TAG from Single VM using PowerCLI

    Posted Apr 13, 2020 07:43 PM

    Thank You very much LucD.

    This is what I did and it works with your help!

    Get-VM VM01 | Get-NsxSecurityTagAssignment |

    Where-Object {$_.securitytag.name -like '*SecurityTag01*'} |

    Remove-NsxSecurityTagAssignment -Confirm:$false

    I have attended a lot of your sessions at VMworld and you always amaze me.  THANKS!