VMware Communities > Developer Community > VI Toolkit (For Windows) > Discussions

This Question is Not Answered

1 "correct" answer available (10 pts) 2 "helpful" answers available (6 pts)
2 Replies Last post: Apr 26, 2008 1:43 PM by halr9000
Reply

get-vmguest should return $null when tools not running

Apr 25, 2008 5:47 PM

Click to view halr9000's profile Expert halr9000 424 posts since
Jun 7, 2007
Another one for VMware, you guys feel free to leave comments supporting my case. :D

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 (http://powerscripting.net)

Reply Re: get-vmguest should return $null when tools not running Apr 26, 2008 12:19 PM
Click to view c_shanklin's profile Expert c_shanklin 245 posts since
Dec 3, 2007
VMware

Hal,

How do you differentiate between not running and not installed?

Reply Re: get-vmguest should return $null when tools not running Apr 26, 2008 1:43 PM
in response to: c_shanklin
Click to view halr9000's profile Expert halr9000 424 posts since
Jun 7, 2007
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)
Actions