VMware Cloud Community
glennmarriott
Contributor
Contributor

Seeking assistance with Tagging Query - get-vm | ?{ (get-tagassignment $_) -eq $null}

Hello and thank you for time and help with my issue.  Much appreciated.

Currently I am running the Docker Power CLI on my mac and I am running a query that I believe would return all systems that are not tagged.  I get the error shown below however after the error, I get a result.  Is this an issue with the query and if so can I get it to run in such a way it doesn't error?  I am still researching the Unable to connect to Inventory Service error at this time so I am asking for some assistance to help me achieve the following goals.

Goals / Scripts needed.

1.  Get a list of all VM's that have no tagging.

2.  Get a list of all VM's that have no Category "Billing"

3.  Tag hosts without the Category "Billing" with a number.

Command Executed and ERROR

PS /powershell> get-vm | ?{ (get-tagassignment $_) -eq $null}

get-tagassignment : 04/03/2017 19:08:22 Get-TagAssignment Unable to connect to the Inventory Service at 'https:REDACTED/invsvc' which is required for the tagging functionality. Additional info: An error occurred while sending the request.

At line:1 char:14

+ get-vm | ?{ (get-tagassignment $_) -eq $null}

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

    + CategoryInfo          : InvalidOperation: (:) [Get-TagAssignment], ViError

    + FullyQualifiedErrorId : ViCore_InventoryServiceProxy_CreateConnectInventoryServiceExceptionWrapper,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.GetTagAssignment

Name                 PowerState Num CPUs MemoryGB

----                 ---------- -------- --------

172-23-22-12   PoweredOn  4        14.500

get-tagassignment : 04/03/2017 19:08:28 Get-TagAssignment An unexpected error has occurred: An error occurred while sending the request..

At line:1 char:14

+ get-vm | ?{ (get-tagassignment $_) -eq $null}

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

    + CategoryInfo          : InvalidOperation: (:) [Get-TagAssignment], ViError

    + FullyQualifiedErrorId : ViCore_InventoryServiceProxy_TryConvertServerError_UnexpectedError,VMware.VimAutomation.ViCore.Cmdlets.Commands.Tagging.GetTagAssignment

172-23-22-13   PoweredOn  4        14.500

INFO

PS /powershell> Get-PowerCLIVersion

PowerCLI Version

----------------

   VMware PowerCLI Core 1.0 build 4630309

---------------

Component Versions

---------------

   VMware vSphere PowerCLI Component 1.22 build 4630309

   VMware VDS PowerCLI Component 1.21 build 4630309

Regards,

-GB

Tags (1)
0 Kudos
4 Replies
LucD
Leadership
Leadership

Is this by any chance against a vSphere 6.5 release?

Tagging didn't work against vSphere 6.5 some time ago, I don't know if that has been fixed in the mean time.


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

0 Kudos
glennmarriott
Contributor
Contributor

Thanks for asking LucD.  I meant to supply that info in my original post as well.

Name:         VMware vCenter Server

Vendor:       VMware, Inc.

Version:      6.0.0

Build:        3339084

OS type:      linux-x64

API type:     VirtualCenter

API version:  6.0

Product ID:   vpx

Oddly it runs in when I give Opbot posh and the same command.  Only issue I have running it there atm is It comes in chunks and it doesn't give me the full hostname.

Name                 PowerState Num CPUs MemoryGB      

----                 ---------- -------- --------      

10-224-211-120-vx... PoweredOn  4        8.000      

0 Kudos
LucD
Leadership
Leadership

The full hostname is there, it just isn't shown in the output.

Try piping the result to for example a Format-Table.

Get-VM | Format-Table

Update:typo corrected


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

0 Kudos
opvizor
Contributor
Contributor

Luc's answer goes into the right direction, but has a typo and would still not show the full name in some cases.

You should use get-vm | format-table -autosize

0 Kudos