Automation

 View Only
  • 1.  Windows Operating System On-line

    Posted Sep 11, 2009 02:06 PM

    We had an issue yesterday where we needed to quickly get the status of all of our Windows VM's. We needed and still need a way to quickly identify if the OS is up and running, not just whether the guest is in a powered on state.

    Most of our guests have "tools old" because we are the process of upgrading to U4. Our environment is 100% Windows.

    Can I report on Guest OS on-line easily? If so, then at the end of the report can it be redirected into an .xls or .csv format?

    vCenter 2.5.0U5

    ESX 3.5.0U3/U4

    Thanks in advance



  • 2.  RE: Windows Operating System On-line

    Posted Sep 11, 2009 02:24 PM

    Hi Troy, I don't know what criteria you wanted to use to determine if the vm is up or where you want to run the script from, but there are a load of great scripts over at maybe one of them would suit/come close to what your looking for?

    Thanks,

    Neil



  • 3.  RE: Windows Operating System On-line

    Posted Sep 11, 2009 02:33 PM

    Thanks Neil! I do in fact have that website bookmarked, but haven't found exactly what I'm looking for there.

    It may be as simple as the code below, but I wanted to roll it all up into something easier if there is a way.

    Get-VM  | where {$_.PowerState -eq "PoweredOn"} | Get-VMGuest | select VmName, State



  • 4.  RE: Windows Operating System On-line

    Posted Sep 11, 2009 02:51 PM

    The above code is good, however it doesn't give me exactly what i'm looking for. I would also like to report on powered off guests, which the code above doesn't.

    ...and does "running" mean the OS is on-line? I would assume so, since I believe the running means the VMware Tools service is started. I know i'm asking a lot, but maybe.....



  • 5.  RE: Windows Operating System On-line

    Posted Sep 11, 2009 02:56 PM

    Could you check to see if the tools were running as the OS has to be up for the tools to report a running state?

    EDIT: Or even the vm heartbeat?

    Thanks,

    Neil



  • 6.  RE: Windows Operating System On-line

    Posted Sep 11, 2009 03:07 PM

    the above code does that, if I redirect the output to a .csv it gives me a status of "running" or "not running", which is good. I just need to add more to the script so that it will also report on powered off VM's, or VM's that are in a powered on state, but the OS has not come up. We sometimes have VM's that go down hard and when they reboot they reboot to "no OS found". So the VM is powered on, but the OS is not loaded.

    So If I can quickly identify the powered off VM's or the VM's that are powered on but No OS has loaded, that would be ideal!!



  • 7.  RE: Windows Operating System On-line

    Posted Sep 11, 2009 03:15 PM

    hmm... apart from scripting an array with the power state and the tools state and running a comparision I'm out on this one I'm afraid...

    Thanks,

    Neil



  • 8.  RE: Windows Operating System On-line
    Best Answer

    Posted Sep 11, 2009 07:04 PM

    If I understand the thread correctly you want to be able to find guests that are powered on but where the OS is not running since it's not installed ?

    The following simple script will create a CSV file which reports on different types of states of all your guests.

    $report = @()
    Get-View -ViewType VirtualMachine | %{
    	$row = "" | Select VMname, PowerState, ToolsStatus, GuestHeartbeatStatus
    	$row.VMname = $_.Name
    	$row.PowerState = $_.Summary.Runtime.PowerState
    	$row.ToolsStatus = $_.Guest.ToolsStatus
    	$row.GuestHeartbeatStatus = $_.GuestHeartbeatStatus
    	$report += $row
    }
    $report | Export-Csv "C:\VM-States.csv"
    

    If you look in the CSV and select the guests which have a powerstate of "poweredon" and a GuestHeartbeatStatus of "red" you will have found the guests you were looking for.

    If you want a script that reports only those guests, an if statements in the previous script will do the trick.

    $report = @()
    Get-View -ViewType VirtualMachine | %{
    	$row = "" | Select VMname, PowerState, ToolsStatus, GuestHeartbeatStatus
    	$row.VMname = $_.Name
    	$row.PowerState = $_.Summary.Runtime.PowerState
    	$row.ToolsStatus = $_.Guest.ToolsStatus
    	$row.GuestHeartbeatStatus = $_.GuestHeartbeatStatus
    	if($row.PowerState -eq "poweredon" -and $row.GuestHeartbeatStatus -eq "red"){
    		$report += $row
    	}
    }
    $report | Export-Csv "C:\VM-States.csv"
    

    I hope this is what you're looking for ?



  • 9.  RE: Windows Operating System On-line

    Posted Sep 11, 2009 07:13 PM

    I think something like what you just put together will work great.

    If I understand the thread correctly you want to be able to find guests that are powered on but where the OS is not running since it's not installed ?

    sort of... What happens sometimes when these VM's go down hard, upon reboot they come up with No OS found. A simple reset of the VM gets everything working again.

    I appreciate your help!