VMware Cloud Community
Tigerstolly
Enthusiast
Enthusiast
Jump to solution

How to display Tools version in VM description ?

Hi,

I can display the version of the tools with this

get-vm VMName | % { get-view $_.ID } | select Name, @{ Name="ToolsVersion"; Expression={$_.config.tools.toolsVersion}}

and i can insert text into the description field with this

get-vm name vmname | set-vm -description "blah blah"

But i'm struggling to understand how to get the toolsversion into the description ! I know it can't be hard, but i'm a scripting novice.

Thanks !

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

You could do that like this

$vm = Get-VM <VM-name> 
$version = ($vm | Get-View).config.tools.toolsVersion 
Set-VM -VM $vm -Description $version -Confirm:$false 

or as a one-liner

Get-VM <VM-name> | Set-VM -Description ($_ | Get-View).config.tools.toolsVersion -Confirm:$false


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

View solution in original post

0 Kudos
12 Replies
LucD
Leadership
Leadership
Jump to solution

You could do that like this

$vm = Get-VM <VM-name> 
$version = ($vm | Get-View).config.tools.toolsVersion 
Set-VM -VM $vm -Description $version -Confirm:$false 

or as a one-liner

Get-VM <VM-name> | Set-VM -Description ($_ | Get-View).config.tools.toolsVersion -Confirm:$false


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

0 Kudos
Tigerstolly
Enthusiast
Enthusiast
Jump to solution

Thats great thanks !

Now, to figure out how to append that to the existing descriptions Smiley Happy

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can just concatenate the 2 strings together like this

$vm = Get-VM <VM-name> 
$description = $vm.Description
$version = ($vm | Get-View).config.tools.toolsVersion 
Set-VM -VM $vm -Description ($description + " " + $version) -Confirm:$false 


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

maishsk
Expert
Expert
Jump to solution

LucD - you continually amaze me how simple you can make these things

Thank you very much!
Maish

Systems Administrator & Virtualization Architect

Maish Saidel-Keesing • @maishsk • http://technodrone.blogspot.com • VMTN Moderator • vExpert • Co-author of VMware vSphere Design
0 Kudos
Tigerstolly
Enthusiast
Enthusiast
Jump to solution

Just what i wanted, thanks again !

0 Kudos
wayne_gregory
Contributor
Contributor
Jump to solution

Great post.

I was wondering if there is a way to set this value into a custom field so I can sort VM's on version types.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, adding the tools version to a custom field is possible.

See for details.


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

0 Kudos
wayne_gregory
Contributor
Contributor
Jump to solution

*

Thanks for the prompt reply.

I am a bit new to powershell so please excuse the daft questions. I am trying to run the following as per the link you set

Get-VM "VIEW-TEST-1" | Set-CustomField -name "Version" ($_ | Get-View).config.tools.toolsVersion -Confirm:$false

but I am getting the following;

The argument cannot be null or empty.

At :line:3 char:70

+ Get-VM "VIEW-TEST-1" | Set-CustomField -name "Version" ($_ | Get-View) &lt;&lt;&lt;&lt; .config.tools.toolsVersion -Confirm:$false

Cannot validate argument because it is null.

Thanks in advance

*

0 Kudos
LucD
Leadership
Leadership
Jump to solution

You can do it this way

Get-VM "VIEW-TEST-1" | %{Set-CustomField -Entity $_ -name "Version" -value ( $_ | Get-View ).config.tools.toolsVersion -Confirm:$false}


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

Tigerstolly
Enthusiast
Enthusiast
Jump to solution

I think that putting the tools version in an extra field is a good way of doing it. Sometimes it can look messy when there is already a description in the notes field. This method makes it nice and neat.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

And you can use these custom attributes in the Virtual Machines tab in the VIC.


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

0 Kudos
wayne_gregory
Contributor
Contributor
Jump to solution

That works perfectly, thanks for such a quick response.

0 Kudos