Hi all,
I want to know if it's possible to find on the database or somewhere else a paramater which would allow to know since when a Virtual Machine is power off.
In fact, I want to scan which Virtual Machine are not used and since when...
My Level = vSphere4.1
Tks
That is strange, I always find VmPoweredOffEvent entries, even when the user initiated a Shutdown from with in the guest OS.
You can easily test this.
Get-VIEvent -Start (Get-Date).AddMinutes(-30) -Entity MyVM | Select CreatedTime,@{N="Event";E={$_.GetType().Name}}
You should see the shutdown you initiated
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
this looks like a job best suited for VMware vSphere™ PowerCLI I have moved your discussion.
You can use the Tasks & Events log.
With the Get-VIEvent cmdlet you can fetch the events.
You would want the VmPoweredOff event.
Have a look at my Events – Part 5 : Powered off for more than 1 week ? post.
In the sample scripts I look for text in the event message, which is another way of doing this.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Tks, good idea.
Hi LuCD,
Tks for you answer.
The probleme to check and track the VMPowerOFF event is if the user shutdown its virtual machines via the Operating System itself this event does't exist.
I already try this anyway.
I also thought to check the last modified date of all .vmdk, it works, but it's sometimes hard to match to .vmdk name with the virtual machine name as some virtual machine names was changed after the creation.
Perhaps a combinated scritp can help me ? 1/ list all .vmdk modified since 1 year (example) 2/ match the virtual machine name after ?
tks
That is strange, I always find VmPoweredOffEvent entries, even when the user initiated a Shutdown from with in the guest OS.
You can easily test this.
Get-VIEvent -Start (Get-Date).AddMinutes(-30) -Entity MyVM | Select CreatedTime,@{N="Event";E={$_.GetType().Name}}
You should see the shutdown you initiated
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You're right LuCD,
I had a look only on the events given by the virtual center, but with your cmd I saw the "power off" event ==>
FullFormattedMessage : MyVM on MyESX in MyDatacneter is powered off
But the -Entity parameters does't work.
I will try your previous recommandation via yoru web site, the script seemes to be OK for my case.
I will let you know my result.
Tks.
Hi again 🙂
The script give me only all virtual machine power off, not the virtual machine power off since 1 year in this example.
Sorry I'm not very fluent in PowerCLI scripting.
$vms = (Get-VM | where {$_.PowerState -eq "PoweredOff"}) | %{$_.Name}
$events = Get-VIEvent -Start (Get-Date).AddDays(-365) | where{$_.FullFormattedMessage -like "*is powered off"}
$lastyearVM = $events | %{$_.Vm.Name}
$Since1Year = $vms | where {!($lastyearVM -contains $_)}
$Since1Year > C:\report\VM-Power-OFF-since-1-year.txt
Could you help me ?
tks.
Two remarks;
Get-VIEvent -Start (Get-Date).AddDays(-180) -MaxSamples [int]::MaxValue
This will theoretically return the maximum integer value events
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
1/ I'm testing with the -MaxSamples (500000) parameters to be sure have all events.
I will let you know my result
question : the parameter (Get-Date).AddDays(-365) means I will find all virtual machines power off since more than 1 year in this case ?
2/ I'm not sure the default is 180 days. I checked the database and the table "VPX-EVENTS" return me all events since the beginnig of my infrastructure.
It seems that the default value is "no database retention policy" for vSphere4 and not possible to set it on VI3.
vSphere4 ==>
Tks
Best regards;
1) Yes
I prefer to use [int]::MaxValue instead of a random number on the MaxSamples parameter, that's the maximum value you can store in an [int]
2) Ok, so you should be able to find all events from the last year.
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LuCD
About the paramaters - MaxSamples[int]::MaxValue syntax ==> does it mean in mycase -MaxSample 500000 instead of -Maxsamples (500000)
You should be able to give -MaxSamples 500000
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
I think The script is good for me now.
Tks a lot for your help.
Best Regards.