VMware Cloud Community
RaviMV
Enthusiast
Enthusiast
Jump to solution

Need a script to check VMtools are updated, its only for selected server

Hello Team

I need a script which fetch the VMtools updated report for selected servers.

Regards,

Ravi

Reply
0 Kudos
1 Solution

Accepted Solutions
RaviMV
Enthusiast
Enthusiast
Jump to solution

Finally below script is working...

$vCenter = Read-Host "Enter vCenter Server name"

Connect-VIServer $vCenter

$file = "C:\Temp\vm_list.txt"

$vms = Get-Content $file

Get-VM $vms | Get-view |Select-Object @{N=”VM Name”;E={$_.Name}},@{Name=”VMware Tools”;E={$_.Guest.ToolsStatus}} | Export-CSV 

C:\Temp\VMwareToolsStatus.csv

View solution in original post

Reply
0 Kudos
18 Replies
SpoonTuxedo
Enthusiast
Enthusiast
Jump to solution

Hi RaviMV,

I think this blog entry should give you a good starting point

VM Tools and Virtual Hardware Versions - VMware PowerCLI Blog - VMware Blogs

Reply
0 Kudos
RaviMV
Enthusiast
Enthusiast
Jump to solution

Thank you for the blog.

This is any there options to check only for selected VM's not all.

Reply
0 Kudos
SpoonTuxedo
Enthusiast
Enthusiast
Jump to solution

Hi RaviMV,

I have put together a powershell script to make life a bit easier.

oversizedspoon/Check-VMtools-Current · GitHub

You will just need to specify the Vcenter server and the names of the VM's that you want to check at the top.

Reply
0 Kudos
RaviMV
Enthusiast
Enthusiast
Jump to solution

When I run the script I found below error message

PS

C:\Users\Ravi> C:\Users\Ravi\Desktop\Update Check-VMtools.ps1

 

Name Port User 

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

Indvcenter01 443 VCLASS\vcadmin 

New-VIProperty : Parameter set cannot be resolved using the specified named parameters.

At C:\Users\Ravi\Desktop\Update Check-VMtools.ps1:20 char:1

+ New-VIProperty -Name ToolsVersion -ObjectType VirtualMachine

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

  + CategoryInfo : InvalidArgument: (:) [New-VIProperty], ParameterBindingException

  + FullyQualifiedErrorId : AmbiguousParameterSet,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVIProperty

-ValueFromExtensionProperty : The term '-ValueFromExtensionProperty' is not recognized as the name of a cmdlet, function, script file, or operable

program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

At C:\Users\Ravi\Desktop\Update Check-VMtools.ps1:21 char:1

+ -ValueFromExtensionProperty 'Config.tools.ToolsVersion'

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

  + CategoryInfo : ObjectNotFound: (-ValueFromExtensionProperty:String) [], CommandNotFoundException

  + FullyQualifiedErrorId : CommandNotFoundException

-Force : The term '-Force' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or

if a path was included, verify that the path is correct and try again.

At C:\Users\Ravi\Desktop\Update Check-VMtools.ps1:22 char:1

+ -Force > $Null

+ ~~~~~~

  + CategoryInfo : ObjectNotFound: (-Force:String) [], CommandNotFoundException

  + FullyQualifiedErrorId : CommandNotFoundException

New-VIProperty : Parameter set cannot be resolved using the specified named parameters.

At C:\Users\Ravi\Desktop\Update Check-VMtools.ps1:25 char:1

+ New-VIProperty -Name ToolsVersionStatus -ObjectType VirtualMachine

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

  + CategoryInfo : InvalidArgument: (:) [New-VIProperty], ParameterBindingException

  + FullyQualifiedErrorId : AmbiguousParameterSet,VMware.VimAutomation.ViCore.Cmdlets.Commands.NewVIProperty

-ValueFromExtensionProperty : The term '-ValueFromExtensionProperty' is not recognized as the name of a cmdlet, function, script file, or operable

program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

At C:\Users\Ravi\Desktop\Update Check-VMtools.ps1:26 char:1

+ -ValueFromExtensionProperty 'Guest.ToolsVersionStatus'

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

  + CategoryInfo : ObjectNotFound: (-ValueFromExtensionProperty:String) [], CommandNotFoundException

  + FullyQualifiedErrorId : CommandNotFoundException

-Force : The term '-Force' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or

if a path was included, verify that the path is correct and try again.

At C:\Users\Ravi\Desktop\Update Check-VMtools.ps1:27 char:5

+ -Force > $Null

+ ~~~~~~

  + CategoryInfo : ObjectNotFound: (-Force:String) [], CommandNotFoundException

  + FullyQualifiedErrorId : CommandNotFoundException

Get-VM : 04-Nov-15 1:55:51 PM Get-VM VM with name 'V' was not found using the specified filter(s). 

At C:\Users\Ravi\Desktop\Update Check-VMtools.ps1:33 char:1

+ Get-VM $vmname[$i]| Select Name, Version, ToolsVersion, ToolsVersionS ...

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

  + CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException

  + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : 04-Nov-15 1:55:51 PM Get-VM VM with name 'C' was not found using the specified filter(s). 

At C:\Users\Ravi\Desktop\Update Check-VMtools.ps1:33 char:1

+ Get-VM $vmname[$i]| Select Name, Version, ToolsVersion, ToolsVersionS ...

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

  + CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException

  + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : 04-Nov-15 1:55:51 PM Get-VM VM with name 'S' was not found using the specified filter(s). 

At C:\Users\Ravi\Desktop\Update Check-VMtools.ps1:33 char:1

+ Get-VM $vmname[$i]| Select Name, Version, ToolsVersion, ToolsVersionS ...

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

  + CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException

  + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : 04-Nov-15 1:55:51 PM Get-VM VM with name 'A' was not found using the specified filter(s). 

At C:\Users\Ravi\Desktop\Update Check-VMtools.ps1:33 char:1

+ Get-VM $vmname[$i]| Select Name, Version, ToolsVersion, ToolsVersionS ...

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

  + CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException

  + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Reply
0 Kudos
SpoonTuxedo
Enthusiast
Enthusiast
Jump to solution

What sort of environment are you running this script in?

Is that host you're running this from have powercli installed?

Reply
0 Kudos
RaviMV
Enthusiast
Enthusiast
Jump to solution

I want run this script in production environment, before that I want it check on my home lab..

Totally we have 1500 VMs. in that there are 800+ are not updated.. So in this scenario I can't check all the server status, I want it in simple way which run the script with provided VM's.. I have script to enable " the check the upgrade vmtools during power cycle" for VM's. its only selected VMs. So the same way I'm looking for where can use script for to check the status only provided VM's.  Can you help on this..

I have script syntax which need to be modify for provided servers

$vCenter = Read-Host "Enter vCenter Server name"

Connect-VIServer $vCenter

Write-Host "Name of Cluster: " -nonewline; $Clustername = Read-Host

Get-VM | Get-View | Select-Object @{N=”VM Name”;E={$_.Name}},@{Name=”VMware Tools”;E={$_.Guest.ToolsStatus}} | Export-CSV c:\temp\VMwareToolsStatus.csv

Reply
0 Kudos
RaviMV
Enthusiast
Enthusiast
Jump to solution

Also the VM's are not in single VCenter.. totally we have 4 VCenter.

Reply
0 Kudos
SpoonTuxedo
Enthusiast
Enthusiast
Jump to solution

How do you want to specify the VM's in the script?

Your script combines with mine pretty well so I can put those together if you wanted to define the vm's in a script.

Reply
0 Kudos
RaviMV
Enthusiast
Enthusiast
Jump to solution

Thanks for quick response.

$VC = Read-Host "Enter vCenter Server name"

$Clustername = Read-Host Write-Host "Name of Cluster: "

$VMName = "VM1","VM2"

Instead of mentioning the VM's one by one. Can't we put it in one .txt file ?

Like  Get-Contain C:\temp\Vm.txt  ???  so that it will easy to paste in one txt file.

Is it possible to add in the script ?

Reply
0 Kudos
SpoonTuxedo
Enthusiast
Enthusiast
Jump to solution

Give me a bit of time and I'll have something for you, also I have noticed that the output to csv only lists the last vm checked.

Reply
0 Kudos
RaviMV
Enthusiast
Enthusiast
Jump to solution

Sure. I'll awaiting for your reply.

I have modified few changes .. Not sure this will work out.

Get-Content c:\Temp\vmlist.txt | where {$_.powerstate -ne "PoweredOff" } | where {$_.Guest.ToolsVersionStatus -ne "guestToolsCurrent"} | % { get-view $_.id } | select Name, @{ Name="ToolsVersion"; Expression={$_.config.tools.toolsVersion}}, @{ Name="ToolStatus"; Expression={$_.Guest.ToolsVersionStatus}} | Export-Csv -NoTypeInformation -UseCulture -Path C:\Temp\VMHWandToolsInfo.csv

Reply
0 Kudos
SpoonTuxedo
Enthusiast
Enthusiast
Jump to solution

Hi RaviMV,

I have made a lot of changes to the script so it will work as you have requested.

https://github.com/oversizedspoon/Check-VMtools-Current

I haven't added the extras from your latest post as I didn't see those when working on this current version.

Reply
0 Kudos
RaviMV
Enthusiast
Enthusiast
Jump to solution

Thanks!, I'll check and update you soon..

Reply
0 Kudos
RaviMV
Enthusiast
Enthusiast
Jump to solution

PS C:\Users\Ravi> C:\Users\Ravi\Desktop\VMtools-Script\Check-VMtools.ps1

Enter vCenter Server name: indvcenter01

Write-Host Name of Cluster: : cluster01

Name Port User 

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

Indvcenter01 443 VCLASS\vcadmin 

Get-VM : 06-Nov-15 5:26:39 AM Get-VM VM with name 'vcsa' was not found using the specified filter(s). 

At C:\Users\Ravi\Desktop\VMtools-Script\Check-VMtools.ps1:30 char:34

+ Get-Cluster $ClusterName | Get-VM $_.name | Get-View | Select-O ...

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

  + CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException

  + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

Get-VM : 06-Nov-15 5:26:39 AM Get-VM VM with name 'winxp' was not found using the specified filter(s). 

At C:\Users\Ravi\Desktop\VMtools-Script\Check-VMtools.ps1:30 char:34

+ Get-Cluster $ClusterName | Get-VM $_.name | Get-View | Select-O ...

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

  + CategoryInfo : ObjectNotFound: (:) [Get-VM], VimException

  + FullyQualifiedErrorId : Core_OutputHelper_WriteNotFoundError,VMware.VimAutomation.ViCore.Cmdlets.Commands.GetVM

 

Reply
0 Kudos
SpoonTuxedo
Enthusiast
Enthusiast
Jump to solution

That output looks normal for the script if the VM name is not matched.

I've just tested with the Vms by the wrong name and got the same output, it still generated the csv when the vm name matched.

I haven't put error handling in to the script, could be something to do at a later date.

It will accept VM names that are an exact match or you can use a wildcard like Server*

Reply
0 Kudos
RaviMV
Enthusiast
Enthusiast
Jump to solution

Hi Spoon,

Any update on this plz.........

Reply
0 Kudos
SpoonTuxedo
Enthusiast
Enthusiast
Jump to solution

Hi Ravi,

I have looked into getting error handling into the script, but haven't been able to get it to work at this point. I'll be posting a thread up soon to get some help on that front.

Other then the way the error output when a VM name doesn't match, the script seems to work fine.

Reply
0 Kudos
RaviMV
Enthusiast
Enthusiast
Jump to solution

Finally below script is working...

$vCenter = Read-Host "Enter vCenter Server name"

Connect-VIServer $vCenter

$file = "C:\Temp\vm_list.txt"

$vms = Get-Content $file

Get-VM $vms | Get-view |Select-Object @{N=”VM Name”;E={$_.Name}},@{Name=”VMware Tools”;E={$_.Guest.ToolsStatus}} | Export-CSV 

C:\Temp\VMwareToolsStatus.csv

Reply
0 Kudos