Hi LucD and thank you for the script.
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?
Example:
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).
Name,Owner,BackupJob,Department
VM1,Benny,Backup1,Finance
VM2,Jerry,,Marketing
Tried to modify the script and it do works, but generates an error
# Assign the Tags to the VMs/Host # Allow empty entries on certain VMs in csv $cmdbinfo | Where {$_.($Name) -eq $Tag} | Foreach {
$cmdbinfo | Where {($tag) -and ($_.($Name) -eq $Tag)} | Foreach {
#$cmdbinfo | Where {$_.($Name) -eq $Tag} | Foreach {
Write-Host ".... Assigning $Tag in Category of $Name to $($_.Name)"
New-TagAssignment -Entity $($_.Name) -Tag $tTag | Out-Null
This is the error being throwned every time
New-Tag : Cannot validate argument on parameter 'Name'. The argument is null or empty. Provide an argument that is not
null or empty, and then try the command again.
At C:\Powershell\VMware\TagsImportAssignNEW.ps1:25 char:26
+ $tTag = New-Tag -Name $Tag -Category $tCat -Description "$Tag from ...
+ ~~~~
+ CategoryInfo : InvalidData: (:) [New-Tag], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.Ne
wTag
How can I adjust the script to write-host "Tag missing from input file, skipping..." or similar?
Thanks!