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 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.
See
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi,
Connect-VIServer -Server
Get-VM | Where {$_.PowerState -eq 'poweredOff' } | % {$_ | Get-View; Write-Host $_.Name ; Write-Host $_.Runtime.BootTime }
I hope it helps you.
Thanks
Niket
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
Can you try this:
Get-VM | where {$_.PowerState -eq 'poweredOff' } | %{ $vm = $_ | get-view Write-Host $vm.Name $vm.runtime.boottime }
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
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.
See
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks Luc!
This helps a lot. At least I now know it is a limitation of the VI Toolkit.
I will research using the VI-SDK to get the info I need.
Jim
hi all,
i need this same report but i have a infraestrture vcenter 2.5 not Sphere, is possible ? how ?
Thx.
Regards,
You should be able to use the same script with VC 2.5.
____________
Blog: LucD notes
Twitter: lucd22
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
i can´t to execute this script, i have one error:
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
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I am trying to do the same the createtime value is not the same as what i see in tasks
t
There is indeed a time difference.
The script is using the time the corresponding event was created, not when the Task was actually running.
You could look for TaskEvent entries, and get the actual Task timestamp.
Are there big time differences?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
not it looks ok.
but I am trying to do this now and not able to get my VM name
get-content poweredoffvms.txt | % { get-vm -name $_ | get-vievent -types INfo -maxsamples 1000 | ? {$_.fullformattedmessage -match "Power On"} |Sort-object -property createdtime | select
$vm.name, fullformattedmessage, createdtime}
but not working
Try changing to -MaxSamples ([int]::MaxValue)
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I cant seem to get the Names of the VM column come up with $vm.name
instead of the powered On value, what would be the value to check for powered Off?
Try like this
Get-VM MyVM | Get-VIEvent -Types Info -MaxSamples ([int]::MaxValue) |
Where-Object {$_.fullFormattedMessage -match "Powered Off"} | `
Sort-Object -property createdTime | select -last 1 | %{
Write-Host $_.vm.name $_.createdTime | Out-Default
}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
thanks lucd,
why I am getting these errors
The request failed with HTTP stastus 501: Not implemented on some vms?