ron9999
Contributor
Contributor

VM Tools Status Report with more Infos than the status

Jump to solution

Hallo.

I'm searching for a script that shows me the VM Tools Status like "Tools Version", "Tools running oder not" and "Tools need upgrade" for each vm. I found a little script

$date=get-date -uformat "%Y%m%d-%H%M%S"; get-vm | % { get-view $_.ID } | select Name,

@{ Name="ToolsStatus"; Expression={$_.guest.toolsstatus}},

@{ Name="ToolsVersion"; Expression={$_.config.tools.toolsVersion}} |

sort-object name | export-csv c:\temp\vmtoolsver_$date.txt -NoTypeInformation

but i need additional information like Custom Fields for each VM named "Customer".

Can everyone help me to implement such information in the script?

That would be very nice.

Thanks to all.

Best regards

ron9999

0 Kudos
1 Solution

Accepted Solutions
RvdNieuwendijk
Leadership
Leadership

And another solution is using the CustomFields property of the VM object:

$date = Get-Date -uformat "%Y%m%d-%H%M%S"
Get-VM | `
Select-Object -Property Name, 
@{ Name="ToolsStatus"; Expression={
  $_.ExtensionData.Guest.ToolsStatus}}, 
@{ Name="ToolsVersion"; Expression={
  $_.ExtensionData.Config.Tools.ToolsVersion}},
@{ Name="Customer"; Expression={$_.CustomFields["Customer"]}} | `
Sort-Object -Property Name | `
Export-CSV -Path c:\temp\vmtoolsver_$date.txt -NoTypeInformation

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

0 Kudos
9 Replies
RvdNieuwendijk
Leadership
Leadership

Hi Ron,

I have adapted your script to also return the value of the customer custom field:

$date = Get-Date -uformat "%Y%m%d-%H%M%S"
Get-VM | Get-View | `
Select-Object -Property Name, 
@{ Name="ToolsStatus"; Expression={$_.guest.toolsstatus}}, 
@{ Name="ToolsVersion"; Expression={$_.config.tools.toolsVersion}},
@{ Name="Customer"; Expression={
  (Get-Annotation -Entity (Get-VIObjectByVIView -VIView $_) -CustomAttribute Customer).Value}} | `
Sort-Object -Property Name | Export-CSV -Path c:\temp\vmtoolsver_$date.txt -NoTypeInformation

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
ron9999
Contributor
Contributor

Hi Robert.

Thanks for helping me.

I have tried the script but the Annotation field is empty although it is filled in the environment. I tried some other annotation fields but with same results.

Have you an idea why the fields are empty?

Regards

Ron

0 Kudos
RvdNieuwendijk
Leadership
Leadership

Hi Ron,

it might be that you are using an older PowerCLI version. The latest version is 4.1 U1. You can check your version with the Get-PowerCLIVersion cmdlet. If you do:

Get-VM | Get-Annotation

You should get all the custom fields of all your virtual machines.

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
ron9999
Contributor
Contributor

Hi Robert.

With Get-PowerCLIVersion I got

VMware vSphere PowerCLI 4.1 U1 build 332441.

With Get-VM | Get-Annotation I can see all fiels including the filled values. That is a little bit strange why this isn't working inside the script.

Regards

Ron

0 Kudos
RvdNieuwendijk
Leadership
Leadership

Hi Ron,

the only thing left that I can think of is that the name of custom attribute "Customer" is written different. Maybe you can try with another custom atribute by changing the value behind the -CustomAttribute parameter in the script.

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
ron9999
Contributor
Contributor

Hi Robert,

I tried another attribute but the result was the same. I have no idea what the reason for this behavior is.

Regards

Ron

0 Kudos
RvdNieuwendijk
Leadership
Leadership

Hi Ron,

I made a new version of the script that does basicly the same but doesn't use the Get-View and Get-VIObjectByVIView cmdlets. Can you give it a try?

$date = Get-Date -uformat "%Y%m%d-%H%M%S"
Get-VM | `
Select-Object -Property Name, 
@{ Name="ToolsStatus"; Expression={
  $_.ExtensionData.Guest.ToolsStatus}}, 
@{ Name="ToolsVersion"; Expression={
  $_.ExtensionData.Config.Tools.ToolsVersion}},
@{ Name="Customer"; Expression={
  (Get-Annotation -Entity $_ -CustomAttribute Customer).Value}} | `
Sort-Object -Property Name | `
Export-CSV -Path c:\temp\vmtoolsver_$date.txt -NoTypeInformation

Regards, Robert

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition
0 Kudos
RvdNieuwendijk
Leadership
Leadership

And another solution is using the CustomFields property of the VM object:

$date = Get-Date -uformat "%Y%m%d-%H%M%S"
Get-VM | `
Select-Object -Property Name, 
@{ Name="ToolsStatus"; Expression={
  $_.ExtensionData.Guest.ToolsStatus}}, 
@{ Name="ToolsVersion"; Expression={
  $_.ExtensionData.Config.Tools.ToolsVersion}},
@{ Name="Customer"; Expression={$_.CustomFields["Customer"]}} | `
Sort-Object -Property Name | `
Export-CSV -Path c:\temp\vmtoolsver_$date.txt -NoTypeInformation

Blog: https://rvdnieuwendijk.com/ | Twitter: @rvdnieuwendijk | Author of: https://www.packtpub.com/virtualization-and-cloud/learning-powercli-second-edition

View solution in original post

0 Kudos
ron9999
Contributor
Contributor

Hello Robert.

Thanks for both scripts. Both solutions generate the required information. That was very helpfull.

Thank you.

Regards

Ron

0 Kudos