new-tagassignment value cannot be null

This post was originally published on this site

Hi everyone,

so I am trying to simply add a tag to a series of machines. I have the tag and a vm name in a CSV. every time I run my script my output says value cannot be null. what am i doing wrong.

 

thanks in advance for everyone help.

 

myCSV data example

tag,name

1,”windows 2016″

1,”windows 2012r2″

 

my Script

Import-Csv -Path c:usersnameDocumentstags.csv -UseCulture | %{

#setting variable for name from CSV

$name = $_.Name

#setting variable for tag from CSV

$tags = $_.tag

#used to test that the variables are read into memory,

#$tags

#$name

#trying to add VM name and add a tags

Get-VM -Name $name | New-TagAssignment -Tag $tags -Confirm:$false

#a different way of doing it and it did not work either

#New-TagAssignment -Tag $tags -Entity (Get-Inventory -Name $_.Name)

MY Output

New-TagAssignment : 10/3/2017 2:48:30 PM        New-TagAssignment               Value cannot be null.

Parameter name: collection

At C:UsersnameDesktopadd-tags.ps1:6 char:22

+ Get-VM -Name $name | New-TagAssignment -Tag $tags -Confirm:$false

+                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [New-TagAssignment], VimException

    + FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.NewTag

   Assignment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.