<?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: Importing VM Tags from CSV file in VMware PowerCLI Discussions</title>
    <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422978#M47910</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;B&gt;LucD&lt;/B&gt;​ and thank you for the script. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry for kicking on a old thread, but I have a specific question about the script you provided. How do you adjust the script to take empty parameters into consideration?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;My .csv looks like this, note the ",," on VM2. Category Backup is not mandatory and should indeed be missing on system not included in Veeam backup (which picks up a VM based on tag).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Name,Owner,BackupJob,Department&lt;/P&gt;&lt;P&gt;VM1,Benny,Backup1,Finance&lt;/P&gt;&lt;P&gt;VM2,Jerry,,Marketing&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tried to modify the script and it do works, but generates an error&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="color: #d4d4d4; background-color: #1e1e1e; font-family: Consolas, 'Courier New', monospace;"&gt;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #6a9955;"&gt;# Assign the Tags to the VMs/Host&lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #6a9955;"&gt;# Allow empty entries on certain VMs in csv $cmdbinfo | Where {$_.($Name) -eq $Tag} | Foreach {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="color: #9cdcfe;"&gt;$cmdbinfo&lt;/SPAN&gt; | &lt;SPAN style="color: #c586c0;"&gt;Where&lt;/SPAN&gt; {(&lt;SPAN style="color: #9cdcfe;"&gt;$tag&lt;/SPAN&gt;) -and ($_.(&lt;SPAN style="color: #9cdcfe;"&gt;$Name&lt;/SPAN&gt;) -eq &lt;SPAN style="color: #9cdcfe;"&gt;$Tag&lt;/SPAN&gt;)} | &lt;SPAN style="color: #c586c0;"&gt;Foreach&lt;/SPAN&gt; {&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="color: #6a9955;"&gt;#$cmdbinfo | Where {$_.($Name) -eq $Tag} | Foreach {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #dcdcaa;"&gt;Write-Host&lt;/SPAN&gt; &lt;SPAN style="color: #ce9178;"&gt;".... Assigning &lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;$Tag&lt;/SPAN&gt;&lt;SPAN style="color: #ce9178;"&gt; in Category of &lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;$Name&lt;/SPAN&gt;&lt;SPAN style="color: #ce9178;"&gt; to $($_&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;.Name&lt;/SPAN&gt;&lt;SPAN style="color: #ce9178;"&gt;)"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #dcdcaa;"&gt;New-TagAssignment&lt;/SPAN&gt; -Entity $($_&lt;SPAN style="color: #9cdcfe;"&gt;.Name&lt;/SPAN&gt;) -Tag &lt;SPAN style="color: #9cdcfe;"&gt;$tTag&lt;/SPAN&gt; | &lt;SPAN style="color: #dcdcaa;"&gt;Out-Null&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the error being throwned every time &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt;New-Tag : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt;null or empty, and then try the command again.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt;At C:\Powershell\VMware\TagsImportAssignNEW.ps1:25 char:26&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt;+&amp;nbsp;&amp;nbsp;&amp;nbsp; $tTag = New-Tag -Name $Tag -Category $tCat -Description "$Tag from ...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt;+&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~~~~&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + CategoryInfo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : InvalidData: (:) [New-Tag], ParameterBindingValidationException&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.Ne&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt;&amp;nbsp;&amp;nbsp; wTag&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #303030;"&gt;How can I adjust the script to write-host "Tag missing from input file, skipping..." or similar?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #303030;"&gt;Thanks! &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 15 Mar 2019 10:47:20 GMT</pubDate>
    <dc:creator>BjornJohansson</dc:creator>
    <dc:date>2019-03-15T10:47:20Z</dc:date>
    <item>
      <title>Importing VM Tags from CSV file</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422969#M47901</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I've been struggling to complete a massive import task of assigning upwards of a dozen categories of tags to a few thousand VMs.&lt;/P&gt;&lt;SPAN&gt;&lt;/SPAN&gt;&lt;P&gt;I've started by using Alan Renouf's&lt;A href="http://www.virtu-al.net/2014/11/13/automating-tags-tag-category-creation-assignment-powercli/"&gt;&amp;nbsp;code&lt;/A&gt; to begin the process but I'm only successful at importing one or two categories before the script unexpectedly ends. Anyone else have suggestions?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Oct 2018 16:56:47 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422969#M47901</guid>
      <dc:creator>Jrt1general</dc:creator>
      <dc:date>2018-10-17T16:56:47Z</dc:date>
    </item>
    <item>
      <title>Re: Importing VM Tags from CSV file</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422970#M47902</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No error messages whatsoever?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Oct 2018 17:06:59 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422970#M47902</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2018-10-17T17:06:59Z</dc:date>
    </item>
    <item>
      <title>Re: Importing VM Tags from CSV file</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422971#M47903</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;None. Which makes me think that it's exiting on an existing tag and just ending gracefully. I've nuked all the tags in my test environment, starting from a blank slate and it runs for less than a second and ends without an error. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;get-tag returns nothing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I create a tag manually, get-tag returns that tag.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The file I'm importing is a csv that looks like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Name,Application,Cost Center,Department,GroupA,GroupB,Owner&lt;/P&gt;&lt;P&gt;tagtestvm1,Application A,123,IT,Cat5GroupA,Cat5GroupB,Owner1&lt;/P&gt;&lt;P&gt;tagtestvm2,Application A,1234,IT,Cat5GroupA,Cat5GroupB,Owner2&lt;/P&gt;&lt;P&gt;tagtestvm3,Application A,1235,IT,Cat5GroupA,Cat5GroupB,Owner3&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Oct 2018 17:55:40 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422971#M47903</guid>
      <dc:creator>Jrt1general</dc:creator>
      <dc:date>2018-10-17T17:55:40Z</dc:date>
    </item>
    <item>
      <title>Re: Importing VM Tags from CSV file</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422972#M47904</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Can you try with this variation on Alan's script?&lt;/P&gt;&lt;P style="color: #333333; background-color: #fffffe; font-family: Consolas, 'Courier New', monospace;"&gt;&lt;/P&gt;&lt;DIV&gt;&lt;SPAN style="color: #0000ff;"&gt;Connect-viserver&lt;/SPAN&gt; myvc.corp.local &lt;SPAN style="color: #a9a9a9;"&gt;-&lt;/SPAN&gt;user administrator&lt;SPAN style="color: #00008b;"&gt;@&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;vsphere&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;.local&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;-&lt;/SPAN&gt;pass Pa&lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #008080;"&gt;$&lt;/SPAN&gt;w0rd&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;CMDBInfo&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;=&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff;"&gt;Import-CSV&lt;/SPAN&gt; .\cmdbinfo.csv&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #006400; font-style: italic;"&gt;# Get the header names to use as tag category names&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;TagCatNames&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;=&lt;/SPAN&gt; &lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;cmdbinfo&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;|&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff;"&gt;Get-Member&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;|&lt;/SPAN&gt; &lt;SPAN style="color: #00008b;"&gt;Where&lt;/SPAN&gt; &lt;SPAN style="color: #000000;"&gt;{&lt;/SPAN&gt;&lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #008080;"&gt;_&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;.MemberType&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;-eq&lt;/SPAN&gt; &lt;SPAN style="color: #8b0000;"&gt;"NoteProperty"&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;}&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;|&lt;/SPAN&gt; Select &lt;SPAN style="color: #a9a9a9;"&gt;-&lt;/SPAN&gt;Expand Name&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #006400; font-style: italic;"&gt;# Create the Tag Category if it doesnt exist&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #00008b;"&gt;Foreach&lt;/SPAN&gt; &lt;SPAN style="color: #000000;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;Name&lt;/SPAN&gt; &lt;SPAN style="color: #00008b;"&gt;in&lt;/SPAN&gt; &lt;SPAN style="color: #000000;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;TagCatNames&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;|&lt;/SPAN&gt; &lt;SPAN style="color: #00008b;"&gt;Where&lt;/SPAN&gt; &lt;SPAN style="color: #000000;"&gt;{&lt;/SPAN&gt;&lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #008080;"&gt;_&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;-ne&lt;/SPAN&gt; &lt;SPAN style="color: #8b0000;"&gt;"Name"&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;}))&lt;/SPAN&gt; &lt;SPAN style="color: #000000;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="color: #00008b;"&gt;Try&lt;/SPAN&gt; &lt;SPAN style="color: #000000;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;tCat&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;=&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff;"&gt;Get-TagCategory&lt;/SPAN&gt; &lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;Name&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;-&lt;/SPAN&gt;ErrorAction Stop&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="color: #000000;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="color: #00008b;"&gt;Catch&lt;/SPAN&gt; &lt;SPAN style="color: #000000;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #0000ff;"&gt;Write-Host&lt;/SPAN&gt; &lt;SPAN style="color: #8b0000;"&gt;"Creating Tag Category &lt;/SPAN&gt;&lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="color: #8b0000;"&gt;"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;tCat&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;=&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff;"&gt;New-TagCategory&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;-&lt;/SPAN&gt;Name &lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;Name&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;-&lt;/SPAN&gt;Description &lt;SPAN style="color: #8b0000;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="color: #8b0000;"&gt; from CMDB"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="color: #000000;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="color: #006400; font-style: italic;"&gt;# Create Tags under the Tag Categories&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;UniqueTags&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;=&lt;/SPAN&gt; &lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;cmdbinfo&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;|&lt;/SPAN&gt; Select &lt;SPAN style="color: #a9a9a9;"&gt;-&lt;/SPAN&gt;expand &lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;Name&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;|&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff;"&gt;Get-Unique&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="color: #00008b;"&gt;Foreach&lt;/SPAN&gt; &lt;SPAN style="color: #000000;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;Tag&lt;/SPAN&gt; &lt;SPAN style="color: #00008b;"&gt;in&lt;/SPAN&gt; &lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;UniqueTags&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;)&lt;/SPAN&gt; &lt;SPAN style="color: #000000;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #00008b;"&gt;Try&lt;/SPAN&gt; &lt;SPAN style="color: #000000;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;tTag&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;=&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff;"&gt;Get-Tag&lt;/SPAN&gt; &lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;Tag&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;-&lt;/SPAN&gt;Category &lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;tCat&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;-&lt;/SPAN&gt;ErrorAction Stop&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #000000;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #00008b;"&gt;Catch&lt;/SPAN&gt; &lt;SPAN style="color: #000000;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #0000ff;"&gt;Write-Host&lt;/SPAN&gt; &lt;SPAN style="color: #8b0000;"&gt;"..Creating Tag under &lt;/SPAN&gt;&lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="color: #8b0000;"&gt; of &lt;/SPAN&gt;&lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;Tag&lt;/SPAN&gt;&lt;SPAN style="color: #8b0000;"&gt;"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;tTag&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;=&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff;"&gt;New-Tag&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;-&lt;/SPAN&gt;Name &lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;Tag&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;-&lt;/SPAN&gt;Category &lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;tCat&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;-&lt;/SPAN&gt;Description &lt;SPAN style="color: #8b0000;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;Tag&lt;/SPAN&gt;&lt;SPAN style="color: #8b0000;"&gt; from CMDB"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #000000;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #006400; font-style: italic;"&gt;# Assign the Tags to the VMs/Hosts&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;cmdbinfo&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;|&lt;/SPAN&gt; &lt;SPAN style="color: #00008b;"&gt;Where&lt;/SPAN&gt; &lt;SPAN style="color: #000000;"&gt;{&lt;/SPAN&gt;&lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #008080;"&gt;_&lt;/SPAN&gt;.&lt;SPAN style="color: #000000;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;)&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;-eq&lt;/SPAN&gt; &lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;Tag&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;}&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;|&lt;/SPAN&gt; &lt;SPAN style="color: #00008b;"&gt;Foreach&lt;/SPAN&gt; &lt;SPAN style="color: #000000;"&gt;{&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #0000ff;"&gt;Write-Host&lt;/SPAN&gt; &lt;SPAN style="color: #8b0000;"&gt;".... Assigning &lt;/SPAN&gt;&lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;Tag&lt;/SPAN&gt;&lt;SPAN style="color: #8b0000;"&gt; in Category of &lt;/SPAN&gt;&lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="color: #8b0000;"&gt; to &lt;/SPAN&gt;&lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #008080;"&gt;_&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;.Name&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;)&lt;/SPAN&gt;&lt;SPAN style="color: #8b0000;"&gt;"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #0000ff;"&gt;New-TagAssignment&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;-&lt;/SPAN&gt;Entity &lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #008080;"&gt;_&lt;/SPAN&gt;&lt;SPAN style="color: #0000ff;"&gt;.Name&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;)&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;-&lt;/SPAN&gt;Tag &lt;SPAN style="color: #00008b;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;tTag&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;|&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff;"&gt;Out-Null&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #000000;"&gt;}&lt;/SPAN&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="color: #000000;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000;"&gt;}&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Oct 2018 18:25:15 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422972#M47904</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2018-10-17T18:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: Importing VM Tags from CSV file</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422973#M47905</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I was penning this update to my reply above:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="color: #3d3d3d; font-family: &amp;amp;font-size:14px; font-style: normal; font-weight: 400; text-align: left; text-indent: 0px;"&gt;I found the issue, the &lt;STRONG&gt;tag-category&lt;/STRONG&gt; was still populated with the categories of a former import - must have been failing silently then. &lt;/P&gt;&lt;P style="color: #3d3d3d; font-family: &amp;amp;font-size:14px; font-style: normal; font-weight: 400; text-align: left; text-indent: 0px;"&gt;&lt;/P&gt;&lt;P style="color: #3d3d3d; font-family: &amp;amp;font-size:14px; font-style: normal; font-weight: 400; text-align: left; text-indent: 0px;"&gt;I ran your script and it works perfectly without error - even when it encounters duplicates.&lt;/P&gt;&lt;P style="color: #3d3d3d; font-family: &amp;amp;font-size:14px; font-style: normal; font-weight: 400; text-align: left; text-indent: 0px;"&gt;&lt;/P&gt;&lt;P style="color: #3d3d3d; font-family: &amp;amp;font-size:14px; font-style: normal; font-weight: 400; text-align: left; text-indent: 0px;"&gt;One thing I'm looking to improve on, is to populate the description along with the tag. &lt;/P&gt;&lt;P style="color: #3d3d3d; font-family: &amp;amp;font-size:14px; font-style: normal; font-weight: 400; text-align: left; text-indent: 0px;"&gt;&lt;/P&gt;&lt;P style="color: #3d3d3d; font-family: &amp;amp;font-size:14px; font-style: normal; font-weight: 400; text-align: left; text-indent: 0px;"&gt;In the spreadsheet, I was thinking&lt;/P&gt;&lt;P style="color: #3d3d3d; font-family: &amp;amp;font-size:14px; font-style: normal; font-weight: 400; text-align: left; text-indent: 0px;"&gt;&lt;/P&gt;&lt;P style="color: #3d3d3d; font-family: &amp;amp;font-size:14px; font-style: normal; font-weight: 400; text-align: left; text-indent: 0px;"&gt;Name, Category1, ,Category2, ,Category3, ,Category4&lt;/P&gt;&lt;P style="color: #3d3d3d; font-family: &amp;amp;font-size:14px; font-style: normal; font-weight: 400; text-align: left; text-indent: 0px;"&gt;vmname, tag1, tag1 description, tag2, tag2 description,&lt;/P&gt;&lt;P style="color: #3d3d3d; font-family: &amp;amp;font-size:14px; font-style: normal; font-weight: 400; text-align: left; text-indent: 0px;"&gt;&lt;/P&gt;&lt;P style="color: #3d3d3d; font-family: &amp;amp;font-size:14px; font-style: normal; font-weight: 400; text-align: left; text-indent: 0px;"&gt;&lt;/P&gt;&lt;P style="color: #3d3d3d; font-family: &amp;amp;font-size:14px; font-style: normal; font-weight: 400; text-align: left; text-indent: 0px;"&gt;Or maybe make it easier to parse, by using a colon between the tag name and description. &lt;/P&gt;&lt;P style="color: #3d3d3d; font-family: &amp;amp;font-size:14px; font-style: normal; font-weight: 400; text-align: left; text-indent: 0px;"&gt;&lt;/P&gt;&lt;P style="color: #3d3d3d; font-family: &amp;amp;font-size:14px; font-style: normal; font-weight: 400; text-align: left; text-indent: 0px;"&gt;Name, Category1,Category2,Category3,Category4&lt;/P&gt;&lt;P style="color: #3d3d3d; font-family: &amp;amp;font-size:14px; font-style: normal; font-weight: 400; text-align: left; text-indent: 0px;"&gt;vmname, tag1:description, tag2:description,&lt;/P&gt;&lt;P style="color: #3d3d3d; font-family: &amp;amp;font-size:14px; font-style: normal; font-weight: 400; text-align: left; text-indent: 0px;"&gt;&lt;/P&gt;&lt;P style="color: #3d3d3d; font-family: &amp;amp;font-size:14px; font-style: normal; font-weight: 400; text-align: left; text-indent: 0px;"&gt;I can get the data in the csv in just about any format and maintain a tight naming convention - which would you recommend? &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Oct 2018 18:56:03 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422973#M47905</guid>
      <dc:creator>Jrt1general</dc:creator>
      <dc:date>2018-10-17T18:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: Importing VM Tags from CSV file</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422974#M47906</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Afaik a Tag can have a description, but not a Tag assignment.&lt;BR /&gt;That would mean, you would need to repeat the same description on each line, which is quite a bit of redundancy in your CSV file.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When you go for the 2nd option, that would mean something like this&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;Name,Application,Cost Center,Department,GroupA,GroupB,Owner&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;TS1,Application A&lt;SPAN style="color: #e23d39;"&gt;:Description&lt;/SPAN&gt;,123,IT,Cat5GroupA,Cat5GroupB,Owner1&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;TS11,Application A&lt;SPAN style="color: #e23d39;"&gt;:Description&lt;/SPAN&gt;,1234,IT,Cat5GroupA,Cat5GroupB,Owner2&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;TS111,Application A&lt;SPAN style="color: #e23d39;"&gt;:Description&lt;/SPAN&gt;,1235,IT,Cat5GroupA,Cat5GroupB,Owner3&lt;/SPAN&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;Wouldn't it be easier to place the TagCategories, the Tags and their description in a separate CSV, and only use the one you have now for Tag assignments?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Oct 2018 19:16:07 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422974#M47906</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2018-10-17T19:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: Importing VM Tags from CSV file</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422975#M47907</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I like the idea of having the descriptions in an secondary file to keep them simple, I'm not sure how to incorporate that into a functional script. I can dump the data into a csv file fairly easily - it would mean the csv file was more bloated than it needed to be but I'm wide open to suggestions!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;On a side note, I changed a value on a VM tag and reran the script found an error (as expected).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;..Creating Tag under Cost Center of 9999999&lt;/P&gt;&lt;P&gt;.... Assigning 9999999 in Category of Cost Center to tagtestvm1&lt;/P&gt;&lt;P&gt;New-TagAssignment : 10/17/2018 2:14:50 PM New-TagAssignment&amp;nbsp; The tag with id 'InventoryServiceTag-83fa7d15-e5e9-48d9-b7b5-dbf27acb365b' cannot be assigned to entity with id 'VirtualMachine-vm-891'. The category of the specified &lt;/P&gt;&lt;P&gt;tag either does not support this entity type or only allows a single tag assignment per entity. &lt;/P&gt;&lt;P&gt;At line:30 char:4&lt;/P&gt;&lt;P&gt;+&amp;nbsp;&amp;nbsp;&amp;nbsp; New-TagAssignment -Entity $($_.Name) -Tag $tTag | Out-Null&lt;/P&gt;&lt;P&gt;+&amp;nbsp;&amp;nbsp;&amp;nbsp; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + CategoryInfo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : InvalidOperation: (Tag:String) [New-TagAssignment], ViError&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + FullyQualifiedErrorId : ViCore_TaggingServiceImpl_TagAssignment_InvalidTagAssociation,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.NewTagAssignment&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Can you help with this? As the csv data may change and need to be applied again. I envision this script being part of a CMDB sync that we're trying to get running as things change the tags would update.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Oct 2018 19:32:03 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422975#M47907</guid>
      <dc:creator>Jrt1general</dc:creator>
      <dc:date>2018-10-17T19:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: Importing VM Tags from CSV file</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422976#M47908</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That is the &lt;STRONG&gt;Cardinality&lt;/STRONG&gt; of the TagCategory.&lt;BR /&gt;Since we didn't specify it, it defaults to &lt;STRONG&gt;Single&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;The other option for cardinality is &lt;STRONG&gt;Multiple&lt;/STRONG&gt;, see the &lt;A href="https://vdc-repo.vmware.com/vmwb-repository/dcr-public/7837e367-fe26-4d85-bd03-84d88261642c/bd07bd63-ee2b-4bf8-bc0c-e7f99d4bfd17/doc/New-TagCategory.html"&gt;New-TagCategory&lt;/A&gt; cmdlet.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It will suffice to just add &lt;STRONG&gt;-Cardinality Multiple&lt;/STRONG&gt; on the New-TagCategory cmdlet in the script&lt;/P&gt;&lt;P&gt;You can change the existing Tag Categories with the &lt;A href="https://vdc-repo.vmware.com/vmwb-repository/dcr-public/7837e367-fe26-4d85-bd03-84d88261642c/bd07bd63-ee2b-4bf8-bc0c-e7f99d4bfd17/doc/Set-TagCategory.html"&gt;Set-TagCategory&lt;/A&gt; cmdlet.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Oct 2018 19:38:48 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422976#M47908</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2018-10-17T19:38:48Z</dc:date>
    </item>
    <item>
      <title>Re: Importing VM Tags from CSV file</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422977#M47909</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Perfect. Thank you.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 17 Oct 2018 19:42:25 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422977#M47909</guid>
      <dc:creator>Jrt1general</dc:creator>
      <dc:date>2018-10-17T19:42:25Z</dc:date>
    </item>
    <item>
      <title>Re: Importing VM Tags from CSV file</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422978#M47910</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;B&gt;LucD&lt;/B&gt;​ and thank you for the script. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Sorry for kicking on a old thread, but I have a specific question about the script you provided. How do you adjust the script to take empty parameters into consideration?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example:&lt;/P&gt;&lt;P&gt;My .csv looks like this, note the ",," on VM2. Category Backup is not mandatory and should indeed be missing on system not included in Veeam backup (which picks up a VM based on tag).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Name,Owner,BackupJob,Department&lt;/P&gt;&lt;P&gt;VM1,Benny,Backup1,Finance&lt;/P&gt;&lt;P&gt;VM2,Jerry,,Marketing&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tried to modify the script and it do works, but generates an error&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="color: #d4d4d4; background-color: #1e1e1e; font-family: Consolas, 'Courier New', monospace;"&gt;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #6a9955;"&gt;# Assign the Tags to the VMs/Host&lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #6a9955;"&gt;# Allow empty entries on certain VMs in csv $cmdbinfo | Where {$_.($Name) -eq $Tag} | Foreach {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="color: #9cdcfe;"&gt;$cmdbinfo&lt;/SPAN&gt; | &lt;SPAN style="color: #c586c0;"&gt;Where&lt;/SPAN&gt; {(&lt;SPAN style="color: #9cdcfe;"&gt;$tag&lt;/SPAN&gt;) -and ($_.(&lt;SPAN style="color: #9cdcfe;"&gt;$Name&lt;/SPAN&gt;) -eq &lt;SPAN style="color: #9cdcfe;"&gt;$Tag&lt;/SPAN&gt;)} | &lt;SPAN style="color: #c586c0;"&gt;Foreach&lt;/SPAN&gt; {&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;SPAN style="color: #6a9955;"&gt;#$cmdbinfo | Where {$_.($Name) -eq $Tag} | Foreach {&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #dcdcaa;"&gt;Write-Host&lt;/SPAN&gt; &lt;SPAN style="color: #ce9178;"&gt;".... Assigning &lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;$Tag&lt;/SPAN&gt;&lt;SPAN style="color: #ce9178;"&gt; in Category of &lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;$Name&lt;/SPAN&gt;&lt;SPAN style="color: #ce9178;"&gt; to $($_&lt;/SPAN&gt;&lt;SPAN style="color: #9cdcfe;"&gt;.Name&lt;/SPAN&gt;&lt;SPAN style="color: #ce9178;"&gt;)"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #dcdcaa;"&gt;New-TagAssignment&lt;/SPAN&gt; -Entity $($_&lt;SPAN style="color: #9cdcfe;"&gt;.Name&lt;/SPAN&gt;) -Tag &lt;SPAN style="color: #9cdcfe;"&gt;$tTag&lt;/SPAN&gt; | &lt;SPAN style="color: #dcdcaa;"&gt;Out-Null&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is the error being throwned every time &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt;New-Tag : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt;null or empty, and then try the command again.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt;At C:\Powershell\VMware\TagsImportAssignNEW.ps1:25 char:26&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt;+&amp;nbsp;&amp;nbsp;&amp;nbsp; $tTag = New-Tag -Name $Tag -Category $tCat -Description "$Tag from ...&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt;+&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ~~~~&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + CategoryInfo&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; : InvalidData: (:) [New-Tag], ParameterBindingValidationException&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; + FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.Ne&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #e23d39;"&gt;&amp;nbsp;&amp;nbsp; wTag&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #303030;"&gt;How can I adjust the script to write-host "Tag missing from input file, skipping..." or similar?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #303030;"&gt;Thanks! &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Mar 2019 10:47:20 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422978#M47910</guid>
      <dc:creator>BjornJohansson</dc:creator>
      <dc:date>2019-03-15T10:47:20Z</dc:date>
    </item>
    <item>
      <title>Re: Importing VM Tags from CSV file</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422979#M47911</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try changing the line to&lt;/P&gt;&lt;P style="color: #333333; background-color: #fffffe; font-family: Consolas, 'Courier New', monospace;"&gt;&lt;/P&gt;&lt;DIV&gt;&amp;nbsp;&amp;nbsp; &lt;SPAN style="color: #000000;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;UniqueTags&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;=&lt;/SPAN&gt; &lt;SPAN style="color: #000000;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;cmdbinfo&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;|&lt;/SPAN&gt; &lt;SPAN style="color: #00008b;"&gt;where&lt;/SPAN&gt; &lt;SPAN style="color: #000000;"&gt;{$&lt;/SPAN&gt;&lt;SPAN style="color: #008080;"&gt;_&lt;/SPAN&gt;.&lt;SPAN style="color: #000000;"&gt;"$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;Name&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;"&lt;/SPAN&gt;&lt;SPAN style="color: #000000;"&gt;}&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;|&lt;/SPAN&gt; Select &lt;SPAN style="color: #a9a9a9;"&gt;-&lt;/SPAN&gt;expand &lt;SPAN style="color: #000000;"&gt;$&lt;/SPAN&gt;&lt;SPAN style="color: #ff4500;"&gt;Name&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;|&lt;/SPAN&gt; &lt;SPAN style="color: #0000ff;"&gt;Sort-Object&lt;/SPAN&gt; &lt;SPAN style="color: #a9a9a9;"&gt;-&lt;/SPAN&gt;Unique&lt;P&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;P&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 15 Mar 2019 11:29:50 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422979#M47911</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2019-03-15T11:29:50Z</dc:date>
    </item>
    <item>
      <title>Re: Importing VM Tags from CSV file</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422980#M47912</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Latest answer ever, but thank you. &lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.vmware.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Mar 2019 15:34:30 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/1422980#M47912</guid>
      <dc:creator>BjornJohansson</dc:creator>
      <dc:date>2019-03-28T15:34:30Z</dc:date>
    </item>
    <item>
      <title>Re: Importing VM Tags from CSV file</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/2829599#M99703</link>
      <description>&lt;P&gt;Hi LucD,&lt;/P&gt;&lt;P&gt;That was a great fix on the script.&amp;nbsp; Thank you!&amp;nbsp; One issue for me is that the script add the tags/categories in different orders on different VMs.&amp;nbsp; Basically, instead of listing Cat1 w/tag, Cat2 w/tag, Cat3 w/tag, Cat4 w/tag on each VM, I get VM1 Cat4 w/tag, w/&amp;nbsp;Cat2 w/tag, Cat3 w/tag, Cat1 w/tag and VM2&amp;nbsp;Cat3 w/tag, Cat2 w/tag, Cat4 w/tag, Cat1 w/tag.&amp;nbsp; Ideally, the tags/categories would be applying&amp;nbsp;Cat1 w/tag, Cat2 w/tag, Cat3 w/tag on every VM.&amp;nbsp; The output looks like it should apply in order, but then they appear visually out of order in vSphere.&amp;nbsp; I appreciate any help you can provide!&lt;/P&gt;&lt;P&gt;.... Assigning Microsoft SQL Server 2016 Ent in Category of Database to VM1&lt;BR /&gt;.... Assigning None in Category of Database to&amp;nbsp;VM2&lt;BR /&gt;.... Assigning Dev in Category of Environment to VM1&lt;BR /&gt;.... Assigning Dev in Category of Environment to VM2&lt;BR /&gt;.... Assigning Analytics in Category of Project to VM1&lt;BR /&gt;.... Assigning Infrastructure-Test in Category of Project to VM2&lt;BR /&gt;.... Assigning None in Category of Software to VM1&lt;BR /&gt;.... Assigning Various Tools in Category of Software to VM2&lt;/P&gt;</description>
      <pubDate>Fri, 12 Feb 2021 23:23:01 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/2829599#M99703</guid>
      <dc:creator>jmarkey</dc:creator>
      <dc:date>2021-02-12T23:23:01Z</dc:date>
    </item>
    <item>
      <title>Re: Importing VM Tags from CSV file</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/2829628#M99705</link>
      <description>&lt;P&gt;Did you try adding a Sort-Object to the line?&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;$TagCatNames = $cmdbinfo | Get-Member | Where {$_.MemberType -eq "NoteProperty"} |
    Sort-Object -Property Name |
    Select -Expand Name

&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 13 Feb 2021 09:23:49 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/2829628#M99705</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2021-02-13T09:23:49Z</dc:date>
    </item>
    <item>
      <title>Re: Importing VM Tags from CSV file</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/2835633#M100362</link>
      <description>&lt;P&gt;Hi LucD-&lt;/P&gt;&lt;P&gt;Thank you for the&amp;nbsp; help!&amp;nbsp; I added the line, but unfortunately I am still getting results that are in different order on each VM.&amp;nbsp; I don't know what I am missing.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;# Get the header names to use as tag category names&lt;/P&gt;&lt;P&gt;$TagCatNames = $cmdbinfo | Get-Member | Where {$_.MemberType -eq "NoteProperty"} | Sort-Object -Property Name | Select -Expand Name&lt;/P&gt;&lt;P&gt;# Create the Tag Category if it doesnt exist&lt;/P&gt;&lt;P&gt;Foreach ($Name in ($TagCatNames | Where {$_ -ne "Name"})) {&lt;/P&gt;&lt;P&gt;Try {&lt;/P&gt;&lt;P&gt;$tCat = Get-TagCategory $Name -ErrorAction Stop&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;Catch {&lt;/P&gt;&lt;P&gt;Write-Host "Creating Tag Category $Name"&lt;/P&gt;&lt;P&gt;$tCat = New-TagCategory -Name $Name -Description "$Name from CMDB"&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# Create Tags under the Tag Categories&lt;/P&gt;&lt;P&gt;$UniqueTags = $cmdbinfo | Select -expand $Name | Get-Unique&lt;/P&gt;&lt;P&gt;Foreach ($Tag in $UniqueTags) {&lt;/P&gt;&lt;P&gt;Try {&lt;/P&gt;&lt;P&gt;$tTag = Get-Tag $Tag -Category $tCat -ErrorAction Stop&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;Catch {&lt;/P&gt;&lt;P&gt;Write-Host "..Creating Tag under $Name of $Tag"&lt;/P&gt;&lt;P&gt;$tTag = New-Tag -Name $Tag -Category $tCat -Description "$Tag from CMDB"&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;# Assign the Tags to the VMs/Hosts&lt;/P&gt;&lt;P&gt;$cmdbinfo | Where {$_.($Name) -eq $Tag} | Foreach {&lt;/P&gt;&lt;P&gt;Write-Host ".... Assigning $Tag in Category of $Name to $($_.Name)"&lt;/P&gt;&lt;P&gt;New-TagAssignment -Entity $($_.Name) -Tag $tTag | Out-Null&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;&lt;P&gt;}&lt;/P&gt;</description>
      <pubDate>Fri, 12 Mar 2021 19:00:47 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/2835633#M100362</guid>
      <dc:creator>jmarkey</dc:creator>
      <dc:date>2021-03-12T19:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: Importing VM Tags from CSV file</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/2835637#M100363</link>
      <description>&lt;P&gt;Some more details I found.&amp;nbsp; It appears to apply them in the same order (not in category order) every time no matter if I do one column /tag category at a time or all at the same time.&amp;nbsp; The PowerCLI display shows them being applied in correct order, but the vsphere side shows them in different orders on each VM.&lt;/P&gt;&lt;P&gt;Name Port User&lt;BR /&gt;---- ---- ----&lt;BR /&gt;10.10 443 VSPHERE.LOCAL\Admin&lt;BR /&gt;.... Assigning Microsoft SQL Server 2016 Ent in Category of Database to ncdad&lt;BR /&gt;.... Assigning None in Category of Database to nccvr&lt;BR /&gt;.... Assigning Dev in Category of Environment to ncdad&lt;BR /&gt;.... Assigning Dev in Category of Environment to nccvr&lt;BR /&gt;.... Assigning Analytics in Category of Project to ncdad&lt;BR /&gt;.... Assigning Infrastructure-Test in Category of Project to nccvr&lt;BR /&gt;.... Assigning None in Category of Software to ncdad&lt;BR /&gt;.... Assigning Various Tools in Category of Software to nccvr&lt;/P&gt;</description>
      <pubDate>Fri, 12 Mar 2021 19:43:00 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/2835637#M100363</guid>
      <dc:creator>jmarkey</dc:creator>
      <dc:date>2021-03-12T19:43:00Z</dc:date>
    </item>
    <item>
      <title>Re: Importing VM Tags from CSV file</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/2835639#M100364</link>
      <description>&lt;P&gt;I'm not sure I fully grasp what you mean by "... &lt;EM&gt;appear visually out of order in vSphere&lt;/EM&gt;"&lt;BR /&gt;Is that the order you see the Tags in the Web Client for each VM?&lt;BR /&gt;Perhaps some screenshots could help me understand&lt;/P&gt;</description>
      <pubDate>Fri, 12 Mar 2021 19:59:28 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/2835639#M100364</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2021-03-12T19:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: Importing VM Tags from CSV file</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/2835642#M100365</link>
      <description>&lt;P&gt;It looks like the first VM does receive it in proper order, but display from the bottom up in vSphere.&amp;nbsp; This would be fine if it was consistent, but once it goes to the second VM, all order is lost.&amp;nbsp; &amp;nbsp;I am testing with two VMs, so I don't have to delete the tags on many VMs when I have failure.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Attached are the orders they are showing in.&amp;nbsp; 2nd reply will have 2nd screenshot as they only accept 1 per reply.&amp;nbsp; Thanks again for all your help!&lt;/P&gt;</description>
      <pubDate>Fri, 12 Mar 2021 20:06:15 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/2835642#M100365</guid>
      <dc:creator>jmarkey</dc:creator>
      <dc:date>2021-03-12T20:06:15Z</dc:date>
    </item>
    <item>
      <title>Re: Importing VM Tags from CSV file</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/2835643#M100366</link>
      <description>&lt;P&gt;2nd Screenshot&lt;/P&gt;</description>
      <pubDate>Fri, 12 Mar 2021 20:07:04 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/2835643#M100366</guid>
      <dc:creator>jmarkey</dc:creator>
      <dc:date>2021-03-12T20:07:04Z</dc:date>
    </item>
    <item>
      <title>Re: Importing VM Tags from CSV file</title>
      <link>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/2835799#M100370</link>
      <description>&lt;P&gt;I did some further testing, and if I add Tags with PowerCLI or via the Web Client, the order they are displayed in the Web Client, seems to be somewhat random.&lt;BR /&gt;And as far as I can tell, there is no way to get them in alphabetical order in the Web Client.&lt;BR /&gt;I suspect that the Web Client is using some kind of internal ID (?) to order them.&lt;/P&gt;</description>
      <pubDate>Sun, 14 Mar 2021 09:28:17 GMT</pubDate>
      <guid>https://communities.vmware.com/t5/VMware-PowerCLI-Discussions/Importing-VM-Tags-from-CSV-file/m-p/2835799#M100370</guid>
      <dc:creator>LucD</dc:creator>
      <dc:date>2021-03-14T09:28:17Z</dc:date>
    </item>
  </channel>
</rss>

