trying to run the following script and getting errors
Script
$VMList = Import-CSV -Path C:\vmw_scripts\test.csv
$vcenter = "myvcenter"
connect-viserver $vcenter
foreach ($vm in $VMList)
{
Get-VM $vm.vm | New-TagAssignment -Tag $vm.tag
}
error
At C:\vmw_scripts\set-tag.ps1:8 char:17
+ Get-VM $vm.vm | New-TagAssignment -Tag $vm.tag
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-TagAssignment], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.NewTagAssignment
New-TagAssignment : 3/10/2018 3:48:59 PM New-TagAssignment Value cannot be null.
Parameter name: collection
At C:\vmw_scripts\set-tag.ps1:8 char:17
+ Get-VM $vm.vm | New-TagAssignment -Tag $vm.tag
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-TagAssignment], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.NewTagAssignment
New-TagAssignment : 3/10/2018 3:49:00 PM New-TagAssignment Value cannot be null.
Parameter name: collection
At C:\vmw_scripts\set-tag.ps1:8 char:17
+ Get-VM $vm.vm | New-TagAssignment -Tag $vm.tag
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-TagAssignment], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.NewTagAssignment
New-TagAssignment : 3/10/2018 3:49:01 PM New-TagAssignment Value cannot be null.
Parameter name: collection
At C:\vmw_scripts\set-tag.ps1:8 char:17
+ Get-VM $vm.vm | New-TagAssignment -Tag $vm.tag
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [New-TagAssignment], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.NewTagAssignment
content of CSV
vm,tag
server1, Application_Services
server1,Migrated
server2, Application_Services
server2,Migrated
PS info
PS C:\vmw_scripts> $psversiontable
Name Value
---- -----
PSVersion 5.1.14393.1944
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.1944
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
Powercli info
PowerCLI Version
----------------
VMware PowerCLI 6.5.1 build 5377412
---------------
Component Versions
---------------
VMware Cis Core PowerCLI Component 6.5 build 6983166
VMware VimAutomation Core PowerCLI Component 6.5 build 6234650
Try this:
$VMList = Import-CSV -Path C:\vmw_scripts\test.csv
$vcenter = "myvcenter"
connect-viserver $vcenter
foreach ($vm in $VMList) {
Get-Tag $vm.tag | New-TagAssignment -Entity $vm.vm
}
thanks, but this them prompts for the Tag and even after I put it in, I get further errors
Supply values for the following parameters:
Tag: Migrated
Get-Tag : 3/11/2018 9:07:20 PM Get-Tag com.vmware.vapi.std.errors.unauthenticated {'messages':
[com.vmware.vapi.std.localizable_message {'id': vapi.method.authentication.required, 'default_message': This method
requires authentication., 'args': []}], 'data':}
At C:\vmw_scripts\set-tag.ps1:9 char:1
+ Get-Tag $vm.tag | New-TagAssignment -Entity $vm.vm
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-Tag], CisException
+ FullyQualifiedErrorId : VMware.VimAutomation.ViCore.Impl.V1.Service.Tagging.Cis.TaggingServiceCisImpl.GetTag.Error,VM
ware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.GetTag
Get-Tag : 3/11/2018 9:07:20 PM Get-Tag Tag with name 'Application_Services' was not found using the specified filter(s).
At C:\vmw_scripts\set-tag.ps1:9 char:1
+ Get-Tag $vm.tag | New-TagAssignment -Entity $vm.vm
+ ~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (:) [Get-Tag], VimException
+ FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.Get
Tag
Just curious, can you run Get-Tag alone with no errors - should produce a list of all tags in your environment.
If you can, is the Application_Services tag in there and spelled the same as your input?
We've been having the same errors for ages on all cmdlets that have anything to do with tags. Did you ever fix it? I started a case now, just want to see this fixed.
I think this started when they moved from PowerCLI 6.5 to Powershell Modules...
Are you getting the error on the Get-Tag run by itself, or when it's qualified?
I'm getting the error on all "tag" related cmdlets, such as Get-VM -Tag "TAG", Get-Tag, Get-TagCategory. Doesn't really matter. Even with a difference powershell version, different logins and administrator@vsphere.local login...Still nothing on the case, VMware is still working on it.
An update on this:
The case is still going, it's taking ages for them to help me/us on this.
It seems however that when we use the Tag cmdlets, we are getting some sort of connection error on port 7444 (STS token service). Not really sure why though because on other stations with the same network access, but with the older PowerCLI instead of Powershell modules it's working fine as it should.