VMware Cloud Community
halr9000
Commander
Commander

get-vmguest should return $null when tools not running

Another one for VMware, you guys feel free to leave comments supporting my case. :smileygrin:

Right now this is what you get when vmtools is not running:

48# $pvm[0] | Get-VMGuest
 
State          IPAddress        OSFullName
-----          ---------        ----------
NotRunning
 
52# [bool]($pvm[0] | Get-VMGuest)
True

To be consistent with other get-* cmdlets in powershell, this command should not return anything, or return $false. Because an object is returned, you cannot simply test for guest presence, you have to 1) remember what the state names are (e.g. running, notrunning), and 2) make an equation testing for the correct string, hoping you remembered it correctly. Alternately, you could do this:

if ( get-vmguest $_ ) { #do stuff here which requires the vmtools }

Hal Rottenberg

Co-Host, PowerScripting Podcast ()

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
Tags (1)
0 Kudos
2 Replies
admin
Immortal
Immortal

Hal,

How do you differentiate between not running and not installed?

0 Kudos
halr9000
Commander
Commander

Good question. I don't know the right answer but it deserves discussion. Correct me if I'm wrong, but from a guest automation point-of-view both cases mean you cannot communicate in-band with the guest. Therefore the end result is the same, you won't be able to work with the members of the guest object.

Hal Rottenberg

Co-Host, PowerScripting Podcast (http://powerscripting.net)

My signature used to be pretty, but then the forum software broked it. vExpert. Microsoft MVP (Windows PowerShell). Author, Podcaster, Speaker. I'm @halr9000
0 Kudos