Hi gurus
I want a list of all powered ON vm with snapshot older than 5 days, I have the following but as you can tell still curving some learning
$PowONvm = Get-VM |where {$_.powerstate -eq "PoweredOn"}| Get-Snapshot | Where {$_.Created -lt (Get-Date).AddDays(-5)} |select vm,name,powerstate
This bring powered off and on vm , can someone help on where I went wrong.
Thanks
The object returned by Get-Snapshot contains a property named VM, under which you find the same object that is returned by Get-VM.
So you could do
Get-VM | Get-Snapshot |
where {$_.VM.powerstate -eq "PoweredOn" -and $_.Created -lt (Get-Date).AddDays(-5)} |
select vm,name,powerstate
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
L.
for some reason it bring the off and on VM
Thanks
That PowerState is the state the VM was in when the snapshot was taken.
When you want to see the current powerstate you can do
Get-VM | Get-Snapshot |
where {$_.VM.powerstate -eq "PoweredOn" -and $_.Created -lt (Get-Date).AddDays(-5)} |
select @{N='VM';E={$_.VM.Name}},Name,@{N='PowerState';E={$_.VM.PowerState}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Hi LucD,
can you help me out on how to use this query for the current powerstate in this script?
You could do something like this
Get-VM | Get-Snapshot |
select @{N='VM';E={$_.VM.Name}},
@{N='Current PowerState';E={$_.VM.PowerState}},
Name,
@{N='PowerState';E={$_.VM.PowerState}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
