VMware Cloud Community
Al_
Enthusiast
Enthusiast
Jump to solution

Simple script to get vms with tags fails

PS D:\temp> get-vm -tag test
get-vm : 10/11/2021 11:59:15 AM Get-VM Value cannot be null.

Guessing this is expected behavior for VMs without the test tag? How do I handle the VMs that do not have a "test" tag, and return a list of VMs with the tag/s I specify? 

Reply
0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could try to upgrade to the latest PowerCLI release.

If that doesn't solve the issue, I suggest opening an SR.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

Reply
0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

No, that is not normal behaviour.
When there are no VM with that specific Tag, nothing should be returned.
No error message either.

Is Get-TagAssignment working for you?

Which PowerCLI version are you using?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Al_
Enthusiast
Enthusiast
Jump to solution

PS D:\temp> Get-TagAssignment
Get-TagAssignment : 10/11/2021 12:22:32 PM Get-TagAssignment com.vmware.vapi.std.errors.unauthenticated {'messages': [com.vmware.vapi.std.localizable_message {'i
d':
vapi.method.authentication.required, 'default_message': This method requires authentication., 'args': [], 'params': , 'localized':}], 'data': , 'error_type': UNAUTHENTICATED,
'challenge':}
At line:1 char:1
+ Get-TagAssignment
+ ~~~~~~~~~~~~~~~~~

 

PS D:\temp> Get-Module -Name VMware.* | Select-Object -Property Name,Version

Name Version
---- -------
VMware.Vim 7.0.0.15939650
VMware.VimAutomation.Cis.Core 12.0.0.15939657
VMware.VimAutomation.Common 12.0.0.15939652
VMware.VimAutomation.Core 12.0.0.15939655
VMware.VimAutomation.Sdk 12.0.0.15939651
VMware.VimAutomation.Vds 12.0.0.15940185
VMware.VimAutomation.vROps 12.0.0.15940184

Reply
0 Kudos
Al_
Enthusiast
Enthusiast
Jump to solution

PowerCLI Version
----------------
VMware PowerCLI 12.0.0 build 15947286
---------------
Component Versions
---------------
VMware Common PowerCLI Component 12.0 build 15939652
VMware Cis Core PowerCLI Component PowerCLI Component 12.0 build 15939657
VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 12.0 build 15939655
VMware VimAutomation Vds Commands PowerCLI Component PowerCLI Component 12.0 build 15940185
VMware VimAutomation vROps PowerCLI Component PowerCLI Component 12.0 build 15940184

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

Try stopping your PS/PowerCLI session, start it again and do a  new Connect-VIServer


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Al_
Enthusiast
Enthusiast
Jump to solution

New PS/PowerCLI session:

PS D:\temp> Get-TagAssignment
Get-TagAssignment : 10/11/2021 12:48:38 PM Get-TagAssignment com.vmware.vapi.std.errors.operation_not_found {'messages': [com.vmware.
{'id':
vapi.method.input.invalid.interface, 'default_message': Cannot find service 'com.vmware.cis.data.svc.resource_model'., 'args': [com.vmware.cis.data.svc.
, 'localized':}], 'data': , 'error_type': OPERATION_NOT_FOUND}
At line:1 char:1
+ Get-TagAssignment
+ ~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-TagAssignment], CisException
+ FullyQualifiedErrorId : VMware.VimAutomation.ViCore.Impl.V1.Service.Tagging.Cis.TaggingServiceCisImpl.GetTagAssignment.Error,VMware.VimAutomation.
gging.GetTagAssignment


Tag Entity
--- ------
application/IDM ***app011
application/IDM ***app012
application/EPO EPO-Test-02
application/EPO ***WEB-EPOAH01
application/EPO ***WEB-EPODR01
agency/*** ***VBLDMZDC2
agency/*** ***WEBDC01
agency/*** ***VBLDC1
agency/*** ***VBLDMZDC3
agency/*** ***DMZICDC02
agency/*** ***PBDC1
agency/*** ***DMZICDC01
agency/*** V1-***WEBDC2
agency/*** ***VBL12TST
agency/*** ***WEBAPPSTEST01
agency/*** LECS-T1-WEB-***
agency/*** ***WEBSTORETEST

 

PS D:\temp> get-vm -tag test
get-vm : 10/11/2021 12:49:48 PM Get-VM Value cannot be null.
Parameter name: collection
At line:1 char:1
+ get-vm -tag test
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Get-VM], VimException
+ FullyQualifiedErrorId : Core_BaseCmdlet_UnknownError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Reply
0 Kudos
Al_
Enthusiast
Enthusiast
Jump to solution

Al__0-1633979055363.png

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

What am I looking at?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Al_
Enthusiast
Enthusiast
Jump to solution

Examples showing: Get-tagAssignment throws an error then returns data, Get-VM -Tag test throws "value cannot be null", and Get-VM -Name *test* is successful.
 
Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

You could try to upgrade to the latest PowerCLI release.

If that doesn't solve the issue, I suggest opening an SR.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
Al_
Enthusiast
Enthusiast
Jump to solution

Will do. Thanks.

Reply
0 Kudos