VMware {code} Community
crosen
Contributor
Contributor
Jump to solution

Finding VM Power State is Inaccurate

I am using the following script to determine the power state of VMs. Regardless of the real state, the result from this script is powerOn. Thanks.

Script:

$VIServer = $Args[0]

$Image = $Args[1]

$User = $Args[2]

$Password = $Args[3]

$FilePath = "C:\Vmware_Healthcheck\Status_$Image.txt"

Add-PSsnapin VMware.VimAutomation.Core

Initialize-VIToolkitEnvironment.ps1

connect-viserver -server $VIServer -user $User -password $Password

$vm = Get-View -ViewType VirtualMachine -Filter @{"Name" = "$Image"}

$hostView = Get-View -ID $vm.Runtime.Host

$hostView.Summary.Runtime | Out-File -FilePath $FilePath

Disconnect-VIServer -Confirm:$False

Result:

ConnectionState : connected

PowerState : poweredOn

InMaintenanceMode : False

BootTime : 4/30/2009 15:05:19

HealthSystemRuntime : VMware.Vim.HealthSystemRuntime

DynamicType :

DynamicProperty :

0 Kudos
1 Solution

Accepted Solutions
fixitchris
Hot Shot
Hot Shot
Jump to solution

Looks like you're returning the host's power state, I think...

$hostView.Summary.Runtime | Out-File -FilePath $FilePath

Take a look at http://www.vmwarescripting.com/index.php?topic=550.msg758#new

View solution in original post

0 Kudos
1 Reply
fixitchris
Hot Shot
Hot Shot
Jump to solution

Looks like you're returning the host's power state, I think...

$hostView.Summary.Runtime | Out-File -FilePath $FilePath

Take a look at http://www.vmwarescripting.com/index.php?topic=550.msg758#new

0 Kudos