<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Applying NSXT Tag to a VM in VMware PowerCLI Discussions</title>
    <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2863077#M102861</link>
    <description>&lt;P&gt;Thank you very much for this, sorry I goofed up the script the first time.&lt;/P&gt;</description>
    <pubDate>Fri, 20 Aug 2021 16:20:27 GMT</pubDate>
    <dc:creator>pamiller21</dc:creator>
    <dc:date>2021-08-20T16:20:27Z</dc:date>
    <item>
      <title>Applying NSXT Tag to a VM</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2861695#M102707</link>
      <description>&lt;P&gt;I am switching over to NSXT from V and trying to figure out how to convert my script to apply NSXT Tags to new VMs being built.&amp;nbsp; Any help would be appreciated&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 19:33:05 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2861695#M102707</guid>
      <dc:creator>pamiller21</dc:creator>
      <dc:date>2021-08-11T19:33:05Z</dc:date>
    </item>
    <item>
      <title>Re: Applying NSXT Tag to a VM</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2861697#M102708</link>
      <description>&lt;P&gt;Have you seen&amp;nbsp;&lt;A href="https://rutgerblom.com/2019/06/09/add-nsx-t-tags-to-virtual-machines-with-powershell/" target="_blank" rel="noopener"&gt;Add NSX-T Tags To Virtual Machines with&amp;nbsp;PowerShell&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 20:02:16 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2861697#M102708</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2021-08-11T20:02:16Z</dc:date>
    </item>
    <item>
      <title>Re: Applying NSXT Tag to a VM</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2861699#M102709</link>
      <description>&lt;P&gt;I did not, my google-fu failed to find it.&amp;nbsp; I am doing some testing and missing something.&amp;nbsp; This seems to be used to apply a tag to nearly a full cluster I am trying to figure out how to filter it down to a single VM.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#############################&lt;BR /&gt;# Connect to vCenter #&lt;BR /&gt;#############################&lt;BR /&gt;Import-Module -Name VMware.PowerCLI&lt;BR /&gt;Set-PowerCLIConfiguration -DisplayDeprecationWarnings $false -InvalidCertificateAction ignore -confirm:$false&lt;BR /&gt;$vc = 'URL'&lt;BR /&gt;$Cred = Import-Clixml /home/scripts/creds/creds.xml&lt;/P&gt;&lt;P&gt;Connect-VIServer $VC -Credential $Cred&lt;/P&gt;&lt;P&gt;#############################&lt;BR /&gt;# Connect to NSX-T #&lt;BR /&gt;#############################&lt;BR /&gt;Import-Module -Name VMware.PowerCLI&lt;BR /&gt;Import-Module PowerNSX&lt;BR /&gt;Set-PowerCLIConfiguration -DisplayDeprecationWarnings $false -InvalidCertificateAction ignore -confirm:$false&lt;BR /&gt;$NSXCred = Import-Clixml /home/scripts/creds/nsxt.xml&lt;BR /&gt;$skipcertcheck = $true&lt;BR /&gt;$AuthMethod = “Basic”&lt;BR /&gt;$NSXMgr = ”URL”&lt;BR /&gt;$policyapi = "/policy/api/v1"&lt;BR /&gt;$base_url = ( "https://" + $NSXMgr + $policyapi )&lt;BR /&gt;$posturl = "https://$NSXMgr/api/v1/fabric/virtual-machines?action=update_tags"&lt;/P&gt;&lt;P&gt;$NSXTag = 'TAG'&lt;BR /&gt;$vm = 'SINGLE VM'&lt;BR /&gt;$vms = Get-VM $vm | ForEach-Object { $_ | Get-View }&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;foreach ($vm in $vms) {&lt;BR /&gt;$vmid = $vm.Config.InstanceUuid }&lt;/P&gt;&lt;P&gt;$geturl = "https://$NSXMgr/api/v1/fabric/virtual-machines?external_id=$vmid&amp;amp;included_fields=tags"&lt;BR /&gt;$getrequest = Invoke-RestMethod -Uri $geturl -Authentication Basic -Credential $nsxcred -Method Get -ContentType "application/json" -SkipCertificateCheck&lt;BR /&gt;$getresult = $getrequest.results | ConvertTo-Json -Compress&lt;BR /&gt;$currenttags = [regex]::match($getresult,'\[([^\)]+)\]').Groups[1].Value&lt;/P&gt;&lt;P&gt;$JSON = @"&lt;BR /&gt;{"external_id":"$vmid","tags": [{"scope":"$newscope","tag":"$NSXTag"},$currenttags]}&lt;BR /&gt;"@&lt;/P&gt;&lt;P&gt;Invoke-RestMethod -Uri $posturl -Authentication Basic -Credential $NSXCred -Method Post -Body $JSON -ContentType "application/json" -SkipCertificateCheck&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 20:35:00 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2861699#M102709</guid>
      <dc:creator>pamiller21</dc:creator>
      <dc:date>2021-08-11T20:35:00Z</dc:date>
    </item>
    <item>
      <title>Re: Applying NSXT Tag to a VM</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2861702#M102711</link>
      <description>&lt;P&gt;I think the script is for a single VM, the&amp;nbsp;&lt;SPAN&gt;&lt;STRONG&gt;$vm = 'SINGLE VM'&lt;/STRONG&gt; line seems to indicate that.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 20:45:22 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2861702#M102711</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2021-08-11T20:45:22Z</dc:date>
    </item>
    <item>
      <title>Re: Applying NSXT Tag to a VM</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2861704#M102713</link>
      <description>&lt;P&gt;What I pasted there was my mangled transformation of the site's script.&amp;nbsp; It doesn't seem to apply a tag to that single vm or do anything.&amp;nbsp; Not sure how to make it do that.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 20:47:38 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2861704#M102713</guid>
      <dc:creator>pamiller21</dc:creator>
      <dc:date>2021-08-11T20:47:38Z</dc:date>
    </item>
    <item>
      <title>Re: Applying NSXT Tag to a VM</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2861706#M102715</link>
      <description>&lt;P&gt;You need to define $newscope variable is what it looks like.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 20:58:32 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2861706#M102715</guid>
      <dc:creator>Zsoldier</dc:creator>
      <dc:date>2021-08-11T20:58:32Z</dc:date>
    </item>
    <item>
      <title>Re: Applying NSXT Tag to a VM</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2861708#M102717</link>
      <description>&lt;P&gt;Somewhere that said it was optional, I don't have a scoped defined on my tag either so not sure what to put.&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 21:00:25 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2861708#M102717</guid>
      <dc:creator>pamiller21</dc:creator>
      <dc:date>2021-08-11T21:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: Applying NSXT Tag to a VM</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2861717#M102718</link>
      <description>&lt;P&gt;Scope can be anything really.&amp;nbsp; There are also other methods of tag updates available depending on version you are working against.&amp;nbsp; Which NSX-T version are you using?&amp;nbsp; 3.1.2 gives you more options outside of just update tag to simplify your scripting too.&amp;nbsp; 2.5.x limits to just update.&lt;/P&gt;&lt;P&gt;&lt;A href="https://vdc-download.vmware.com/vmwb-repository/dcr-public/d6de7a5e-636f-4677-8dbd-6f4ba91fa5e0/36b4881c-41cd-4c46-81d1-b2ca3a6c693b/api_includes/system_administration_configuration_fabric_inventory_virtual_machines.html" target="_blank"&gt;https://vdc-download.vmware.com/vmwb-repository/dcr-public/d6de7a5e-636f-4677-8dbd-6f4ba91fa5e0/36b4881c-41cd-4c46-81d1-b2ca3a6c693b/api_includes/system_administration_configuration_fabric_inventory_virtual_machines.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Aug 2021 21:21:04 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2861717#M102718</guid>
      <dc:creator>Zsoldier</dc:creator>
      <dc:date>2021-08-11T21:21:04Z</dc:date>
    </item>
    <item>
      <title>Re: Applying NSXT Tag to a VM</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2861996#M102764</link>
      <description>&lt;P&gt;I am running 3.1.2, so can I put in any random keyword in the scope field?&lt;/P&gt;</description>
      <pubDate>Fri, 13 Aug 2021 14:11:35 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2861996#M102764</guid>
      <dc:creator>pamiller21</dc:creator>
      <dc:date>2021-08-13T14:11:35Z</dc:date>
    </item>
    <item>
      <title>Re: Applying NSXT Tag to a VM</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2862181#M102780</link>
      <description>&lt;P&gt;&lt;a href="https://communities.vmware.com/t5/user/viewprofilepage/user-id/256147"&gt;@LucD&lt;/a&gt;&amp;nbsp;When I run the code you sent I get this error:&lt;/P&gt;&lt;P&gt;ERROR:&lt;/P&gt;&lt;P&gt;Invoke-RestMethod: {&lt;BR /&gt;"httpStatus" : "BAD_REQUEST",&lt;BR /&gt;"error_code" : 220,&lt;BR /&gt;"module_name" : "common-services",&lt;BR /&gt;"error_message" : "Unexpected character (']' (code 93)): expected a value"&lt;/P&gt;&lt;P&gt;CODE:&lt;/P&gt;&lt;P&gt;#############################&lt;BR /&gt;# Connect to vCenter #&lt;BR /&gt;#############################&lt;BR /&gt;Import-Module -Name VMware.PowerCLI&lt;BR /&gt;Set-PowerCLIConfiguration -DisplayDeprecationWarnings $false -InvalidCertificateAction ignore -confirm:$false&lt;BR /&gt;$vc = 'URL'&lt;BR /&gt;$Cred = Import-Clixml /home/scripts/creds/creds.xml&lt;/P&gt;&lt;P&gt;Connect-VIServer $VC -Credential $Cred&lt;/P&gt;&lt;P&gt;#############################&lt;BR /&gt;# Connect to NSX-T #&lt;BR /&gt;#############################&lt;BR /&gt;Import-Module -Name VMware.PowerCLI&lt;BR /&gt;Import-Module PowerNSX&lt;BR /&gt;Set-PowerCLIConfiguration -DisplayDeprecationWarnings $false -InvalidCertificateAction ignore -confirm:$false&lt;BR /&gt;$NSXCred = Import-Clixml /home/scripts/creds/nsxt.xml&lt;BR /&gt;$skipcertcheck = $true&lt;BR /&gt;$AuthMethod = “Basic”&lt;BR /&gt;$NSXMgr = ”URL”&lt;BR /&gt;$policyapi = "/policy/api/v1"&lt;BR /&gt;$base_url = ( "https://" + $NSXMgr + $policyapi )&lt;BR /&gt;$posturl = "https://$NSXMgr/api/v1/fabric/virtual-machines?action=update_tags"&lt;/P&gt;&lt;P&gt;$NSXTag = 'TAG'&lt;BR /&gt;$vmName = 'SINGLE VM'&lt;BR /&gt;$vm = Get-VM -Name $vmName&lt;/P&gt;&lt;P&gt;$vmid = $vm.ExtensionData.Config.InstanceUuid&lt;/P&gt;&lt;P&gt;$geturl = "https://$NSXMgr/api/v1/fabric/virtual-machines?external_id=$vmid&amp;amp;included_fields=tags"&lt;BR /&gt;$getrequest = Invoke-RestMethod -Uri $geturl -Authentication Basic -Credential $nsxcred -Method Get -ContentType "application/json" -SkipCertificateCheck&lt;BR /&gt;$getresult = $getrequest.results | ConvertTo-Json -Compress&lt;BR /&gt;$currenttags = [regex]::match($getresult,'\[([^\)]+)\]').Groups[1].Value&lt;/P&gt;&lt;P&gt;$JSON = @"&lt;BR /&gt;{"external_id":"$vmid","tags": [{"scope":"$newscope","tag":"$NSXTag"},$currenttags]}&lt;BR /&gt;"@&lt;/P&gt;&lt;P&gt;Invoke-RestMethod -Uri $posturl -Authentication Basic -Credential $NSXCred -Method Post -Body $JSON -ContentType "application/json" -SkipCertificateCheck&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 03:25:43 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2862181#M102780</guid>
      <dc:creator>pamiller21</dc:creator>
      <dc:date>2021-08-16T03:25:43Z</dc:date>
    </item>
    <item>
      <title>Re: Applying NSXT Tag to a VM</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2862286#M102797</link>
      <description>&lt;P&gt;Basically means malformed json.&amp;nbsp; Here is script cleaned up a bit.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;#Requires -Module vmware.powercli
$Credential = Get-Credential
$skipcertcheck = $true
$AuthMethod = “Basic”
$NSXMgr=”0.0.0.0”
$apiendpoint = "/api/v1/fabric"
$base_url = ("https://" + $NSXMgr + $apiendpoint)
$tag = "Naka"
$scope = "NakaScope"

$vms = Get-VM -Name nakabuntu | Get-View -Property "Config"
# Add Tags to existing tags (Valid for NSX-T 3.1.2, previous versions only have update_tag)
$endpoint = "/virtual-machines"
$action = "add_tags"
Foreach ($vm in $vms)
{
    $vmid = $vm.Config.InstanceUuid
    $JSON = "
    {
        `"external_id`":`"$vmid`",
        `"tags`": [
            {
                `"scope`":`"$scope`",
                `"tag`":`"$Tag`"
            }
            ]
    }
    "

    $Data = Invoke-restmethod -Uri ($base_url + $EndPoint + "?action=" + $action) -Method POST -Body $JSON -ContentType 'application/json' -Credential $Credential -SkipCertificateCheck:$skipcertcheck -Authentication:$AuthMethod
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 17:39:25 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2862286#M102797</guid>
      <dc:creator>Zsoldier</dc:creator>
      <dc:date>2021-08-16T17:39:25Z</dc:date>
    </item>
    <item>
      <title>Re: Applying NSXT Tag to a VM</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2862981#M102849</link>
      <description>&lt;P&gt;I ran that code and it didn't give me any errors, but also didn't do the tag.&amp;nbsp; Any idea what I can check into now?&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 03:27:37 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2862981#M102849</guid>
      <dc:creator>pamiller21</dc:creator>
      <dc:date>2021-08-20T03:27:37Z</dc:date>
    </item>
    <item>
      <title>Re: Applying NSXT Tag to a VM</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2863031#M102853</link>
      <description>&lt;P&gt;Did you change the get-vm filter?&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 12:32:48 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2863031#M102853</guid>
      <dc:creator>Zsoldier</dc:creator>
      <dc:date>2021-08-20T12:32:48Z</dc:date>
    </item>
    <item>
      <title>Re: Applying NSXT Tag to a VM</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2863034#M102854</link>
      <description>&lt;P&gt;Ya I updated it to a variable and set the variable earlier, here is exactly what I tried:&lt;/P&gt;&lt;P&gt;#############################&lt;BR /&gt;# Connect to vCenter #&lt;BR /&gt;#############################&lt;BR /&gt;Import-Module -Name VMware.PowerCLI&lt;BR /&gt;Set-PowerCLIConfiguration -DisplayDeprecationWarnings $false -InvalidCertificateAction ignore -confirm:$false&lt;BR /&gt;$vc = 'vcsa.ruralnex.com'&lt;BR /&gt;$Cred = Import-Clixml /home/scripts/creds/creds.xml&lt;/P&gt;&lt;P&gt;Connect-VIServer $VC -Credential $Cred&lt;/P&gt;&lt;P&gt;#############################&lt;BR /&gt;# Connect to NSX-T #&lt;BR /&gt;#############################&lt;BR /&gt;Import-Module -Name VMware.PowerCLI&lt;BR /&gt;Import-Module PowerNSX&lt;BR /&gt;Set-PowerCLIConfiguration -DisplayDeprecationWarnings $false -InvalidCertificateAction ignore -confirm:$false&lt;BR /&gt;$NSXCred = Import-Clixml /home/scripts/creds/nsxt.xml&lt;BR /&gt;$skipcertcheck = $true&lt;BR /&gt;$AuthMethod = “Basic”&lt;BR /&gt;$NSXMgr = ”URL”&lt;BR /&gt;$policyapi = "/policy/api/v1"&lt;BR /&gt;#$base_url = ( "https://" + $NSXMgr + $policyapi )&lt;BR /&gt;$base_url = ("https://" + $NSXMgr + $apiendpoint)&lt;BR /&gt;$posturl = "https://$NSXMgr/api/v1/fabric/virtual-machines?action=update_tags"&lt;/P&gt;&lt;P&gt;$NSXTag = 'Alerta'&lt;BR /&gt;$vmName = 'alerta03_replica'&lt;BR /&gt;$vm = Get-VM -Name $vmName&lt;/P&gt;&lt;P&gt;##Requires -Module vmware.powercli&lt;BR /&gt;#$Credential = Get-Credential&lt;BR /&gt;#$skipcertcheck = $true&lt;BR /&gt;#$AuthMethod = “Basic”&lt;BR /&gt;#$NSXMgr=”0.0.0.0”&lt;BR /&gt;#$apiendpoint = "/api/v1/fabric"&lt;/P&gt;&lt;P&gt;#$tag = "Naka"&lt;BR /&gt;$scope = "Servers"&lt;/P&gt;&lt;P&gt;$vms = Get-VM -Name $vmName | Get-View -Property "Config"&lt;BR /&gt;# Add Tags to existing tags (Valid for NSX-T 3.1.2, previous versions only have update_tag)&lt;BR /&gt;$endpoint = "/virtual-machines"&lt;BR /&gt;$action = "add_tags"&lt;BR /&gt;Foreach ($vm in $vms)&lt;BR /&gt;{&lt;BR /&gt;$vmid = $vm.Config.InstanceUuid&lt;BR /&gt;$JSON = "&lt;BR /&gt;{&lt;BR /&gt;`"external_id`":`"$vmid`",&lt;BR /&gt;`"tags`": [&lt;BR /&gt;{&lt;BR /&gt;# `"scope`":`"$scope`",&lt;BR /&gt;`"tag`":`"$NSXTag`"&lt;BR /&gt;}&lt;BR /&gt;]&lt;BR /&gt;}&lt;BR /&gt;"&lt;/P&gt;&lt;P&gt;$Data = Invoke-restmethod -Uri ($base_url + $EndPoint + "?action=" + $action) -Method POST -Body $JSON -ContentType 'application/json' -Credential $NSXCred -SkipCertificateCheck:$skipcertcheck -Authentication:$AuthMethod&lt;BR /&gt;}&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 13:08:58 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2863034#M102854</guid>
      <dc:creator>pamiller21</dc:creator>
      <dc:date>2021-08-20T13:08:58Z</dc:date>
    </item>
    <item>
      <title>Re: Applying NSXT Tag to a VM</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2863049#M102859</link>
      <description>&lt;P&gt;Have you tried running the code I posted above verbatim?&amp;nbsp; There are lots of problems w/ the way that you've modified your script.&amp;nbsp; $apiendpoint is not defined correctly since you've commented it out and is not before you capture your base_url.&amp;nbsp; Commenting out scope doesn't work the way you've done here.&amp;nbsp; I've cleaned up my script example further so you can omit scope if you don't need it and change the get-vm call to base on a vmnamefilter variable.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, you do not need to import the PowerNSX module unless you are making additional calls to an NSX-V instance in the same script.&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;#Requires -Module vmware.powercli
$Credential = Get-Credential
$skipcertcheck = $true
$AuthMethod = “Basic”
$NSXMgr=”0.0.0.0”
$apiendpoint = "/api/v1/fabric"
$base_url = ("https://" + $NSXMgr + $apiendpoint)
$tag = "Naka"
$scope = "NakaScope"  # If scope not required, simply define as $null or ""
$vmnamefilter = "nakabuntu" # Not required.  Will loop through all VM's otherwise.

$vms = Get-VM $vmnamefilter | Get-View -Property "Config"
# Add Tags to existing tags (Valid for NSX-T 3.1.2, previous versions only have update_tag)
$endpoint = "/virtual-machines"
$action = "add_tags"
Foreach ($vm in $vms)
{
    $vmid = $vm.Config.InstanceUuid
    If ([string]::IsNullOrWhiteSpace($Scope)){
    $JSON = "
    {
        `"external_id`":`"$vmid`",
        `"tags`": [
            {
                `"tag`":`"$Tag`"
            }
            ]
    }
    "
    }
    Else{
        $JSON = "
        {
            `"external_id`":`"$vmid`",
            `"tags`": [
                {
                    `"scope`":`"$scope`",
                    `"tag`":`"$Tag`"
                }
                ]
        }
        "
    }
    $Data = Invoke-restmethod -Uri ($base_url + $EndPoint + "?action=" + $action) -Method POST -Body $JSON -ContentType 'application/json' -Credential $Credential -SkipCertificateCheck:$skipcertcheck -Authentication:$AuthMethod
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 14:17:36 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2863049#M102859</guid>
      <dc:creator>Zsoldier</dc:creator>
      <dc:date>2021-08-20T14:17:36Z</dc:date>
    </item>
    <item>
      <title>Re: Applying NSXT Tag to a VM</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2863077#M102861</link>
      <description>&lt;P&gt;Thank you very much for this, sorry I goofed up the script the first time.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Aug 2021 16:20:27 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2863077#M102861</guid>
      <dc:creator>pamiller21</dc:creator>
      <dc:date>2021-08-20T16:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: Applying NSXT Tag to a VM</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2867602#M103340</link>
      <description>&lt;P&gt;Thank you, with a few tweaks my rollout script worked the way I want again.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Sep 2021 13:32:46 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2867602#M103340</guid>
      <dc:creator>cvv2</dc:creator>
      <dc:date>2021-09-20T13:32:46Z</dc:date>
    </item>
    <item>
      <title>Re: Applying NSXT Tag to a VM</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2929051#M108319</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I´m just trying to use this script, but I´m not able to connect to nsx via invoke-restmethod. I use the complete script...&lt;/P&gt;&lt;P&gt;&amp;nbsp;$Data = Invoke-restmethod -Uri ($base_url + $EndPoint + "?action=" + $action) -Method POST -Body $JSON -ContentType 'application/json' -Credential $Credential -SkipCertificateCheck:$skipcertcheck -Authentication:$AuthMethod&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Invoke-RestMethod : A parameter cannot be found that matches parameter name 'SkipCertificateCheck'.&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;At line:1 char:164&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;+ ... lication/json' -Credential $Credential -SkipCertificateCheck:$skipcer ...&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;+ ~~~~~~~~~~~~~~~~~~~~~~&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;+ CategoryInfo : InvalidArgument: (:) [Invoke-RestMethod], ParameterBindingException&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.InvokeRestMethodCommand&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Sep 2022 09:15:48 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2929051#M108319</guid>
      <dc:creator>vespavbb</dc:creator>
      <dc:date>2022-09-15T09:15:48Z</dc:date>
    </item>
    <item>
      <title>Re: Applying NSXT Tag to a VM</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2933057#M108702</link>
      <description>&lt;P&gt;SkipCertificateCheck is only available via Powershell Core I believe.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2022 16:25:49 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2933057#M108702</guid>
      <dc:creator>Zsoldier</dc:creator>
      <dc:date>2022-10-11T16:25:49Z</dc:date>
    </item>
    <item>
      <title>Re: Applying NSXT Tag to a VM</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2933072#M108704</link>
      <description>&lt;P&gt;That is correct&lt;/P&gt;</description>
      <pubDate>Tue, 11 Oct 2022 17:50:25 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Applying-NSXT-Tag-to-a-VM/m-p/2933072#M108704</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2022-10-11T17:50:25Z</dc:date>
    </item>
  </channel>
</rss>

