I am trying to pull together a script that will list all my powerd off VMs and then list its last PowerOn.
Anyone have any ideas?
Jim
That didn't work for me. I am looking for some date that the VM was last running.
When I tried that it gave me the fllowing output:
Capability : VMware.Vim.VirtualMachineCapability
Config : VMware.Vim.VirtualMachineConfigInfo
Layout : VMware.Vim.VirtualMachineFileLayout
EnvironmentBrowser : VMware.Vim.ManagedObjectReference
ResourcePool : VMware.Vim.ManagedObjectReference
ResourceConfig : VMware.Vim.ResourceConfigSpec
Runtime : VMware.Vim.VirtualMachineRuntimeInfo
Guest : VMware.Vim.GuestInfo
Summary : VMware.Vim.VirtualMachineSummary
Datastore : {VMware.Vim.ManagedObjectReference}
Network : {VMware.Vim.ManagedObjectReference}
Snapshot :
GuestHeartbeatStatus : gray
Parent : VMware.Vim.ManagedObjectReference
CustomValue : + OverallStatus : green ConfigStatus : green ConfigIssue : {} EffectiveRole : {-1} Permission : {} Name : dsy12512kw DisabledMethod : {RevertToCurrentSnapshot_Task, RemoveAllSnapshots_Task, ResetVM_Task, UnmountToolsInstaller...} RecentTask : {} DeclaredAlarmState : {alarm-4.vm-271, alarm-5.vm-271, alarm-6.vm-271} TriggeredAlarmState : {} +Value :
AvailableField : {Snapshot Size (MB), Snapshots}
MoRef : VMware.Vim.ManagedObjectReference
Client : VMware.Vim.VimClient
dsy12512kw
Thanks
When I run that it gives me the following:
qvmxp6-jmat2 1/1/0001 12:00:00 AM
QSQSEA78SR 1/1/0001 12:00:00 AM
qw3k06r 1/1/0001 12:00:00 AM
qudsea77arc1 1/1/0001 12:00:00 AM
qw3k05du1 1/1/0001 12:00:00 AM
qw2k04du1 1/1/0001 12:00:00 AM
qaoptsoawin32zh 1/1/0001 12:00:00 AM
qaoptsoaw32zhtw 1/1/0001 12:00:00 AM
qaoptsoaw32ptbr 1/1/0001 12:00:00 AM
qorsia80tgt2 1/1/0001 12:00:00 AM
qw3k08 1/1/0001 12:00:00 AM
qw2k07du1 1/1/0001 12:00:00 AM
q10gebs12d 1/1/0001 12:00:00 AM
qw3k04du2 1/1/0001 12:00:00 AM
qor10rhsia80 1/1/0001 12:00:00 AM
qorsia77src 1/1/0001 12:00:00 AM
qw3k06du2 1/1/0001 12:00:00 AM
qw2k06du1 1/1/0001 12:00:00 AM
q10gebs510b 1/27/2009 8:10:51 PM
qaoptsoawin32fr 1/1/0001 12:00:00 AM
qaebsws1 1/1/0001 12:00:00 AM
qw2k05du1 1/1/0001 12:00:00 AM
qvmxp6-nd1 1/21/2009 7:46:55 PM
It appears that it is not finding a date for most of the powered off VMs, Right?
Where is is getting this info? Logs or the VC database?
Any ideas why?
Jim
That is indeed the problem with the bootTime property in the VirtualMachineRuntimeInfo object.
A better approach would be to use the power on event.
Something like this
Get-VM <VM-name> | Get-VIEvent -Types Info -MaxSamples 1000 | `
Where-Object {$_.fullFormattedMessage -match "Power On"} | `
Sort-Object -property createdTime | select -last 1 | %{
Write-Host $_.vm.name $_.createdTime | Out-Default
}
The problem with this method is that is currently a known issue with the Get-VIEvent cmdlet.
The cmdlet returns only 1000 events independent of what you specify in the -maxSmaples parameter.
If the power on is some time ao it could be that it doesn't fall in the last 1000 events.
There is a method to bypass this issue by using the SDK methods.
i can´t to execute this script, i have one error:
Re: Last VM powerOn C:\> & '.\VM Last Poweron Time.ps1'
File C:\VM Last Poweron Time.ps1 cannot be loaded. The file C:\VM Last Poweron
Time.ps1 is not digitally signed. The script will not execute on the system. Pl
ease see "get-help about_signing" for more details..
At line:1 char:2
+ & <<<< '.\VM Last Poweron Time.ps1'
Regards,
I suspect you haven't set the execution policy for PowerShell scripts yet.
Do
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
from the prompt before you start the script.
____________
Blog: LucD notes
Twitter: lucd22
hi,
thx, but now i have a diferent error:
Re: Last VM powerOn C:\> get-vm | ./'VM Last Poweron Time.ps1'
Parameter declarations are a comma-separated list of variable names with option
al initializer expressions.
At C:\VM Last Poweron Time.ps1:9 char:11
+ )] <<<<
Regards,