PowerCLI

 View Only

 Accessing VM Properties

Jump to  Best Answer
ChrisRayDekraSE's profile image
ChrisRayDekraSE posted Apr 04, 2025 04:54 AM

Hello, I'm working on a script that we will use to check several settings on some of our VMs. I've made a list of all of the properties that we want the script to check. The first check to perform is to verify that VMware Tools is running within the Guest OS.

$VM = Get-VM <<VMName>>

$VM.ExtensionData.Guest.ToolsRunningStatus

This returns "guestToolsRunning" if VMware Tools is running within the Guest OS. So far so good. What is not working is this:

$TargetProperty = "ExtensionData.Guest.ToolsRunningStatus"

$VM.$TargetProperty

I've tried wrapping $TargetProperty in single quotes, double quotes, different kinds of brackets: [],{},() but it still returns nothing.

I'm hoping someone can explain why this doesn't work and hopefully a way to get it working! Thanks in advance ;-)

ITSavant's profile image
ITSavant  Best Answer

It's not working because you are converting to a string and trying to traverse an object property tree
You could do it like this, $VM."ExtensionData"."Guest"."ToolsRunningStatus"  but I don't see how that would help.

Why not like this, (plus wicker faster)

$VMViews =  Get-View -ViewType VirtualMachine -Server $vCenter -Property Name, Runtime, Guest | Sort Name
$VMViews | Select Name, @{n='PowerState';e={$_.Runtime.PowerState}}, @{n='ToolsRunningStatus';e={$_.Guest.ToolsRunningStatus}}