How can i get snapshot age more than 3 days but less than 10 days
Something like this?
$now = Get-Date
Get-VM |
Get-Snapshot |
Where {$_.Created -lt $now.AddDays(-3) -and $_.Created -gt $now.AddDays(-10)}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You mean like this?
$now = Get-Date
$snap = Get-VM | Get-Snapshot
$totalSnapSizeGB = $snap | Measure-Object -Property SizeGB -Sum | Select-Object -ExpandProperty Sum
$snap |
Where {$_.Created -lt $now.AddDays(-3) -and $_.Created -gt $now.AddDays(-10)} |
Select @{N='VM';E={$_.VM.Name}},
Name, Created, SizeGB,
@{N='AllSnapShotSizeGB';E={$totalSnapSizeGB}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
You can use the [Math]::Round() method
$now = Get-Date
$snap = Get-VM | Get-Snapshot
$totalSnapSizeGB = $snap | Measure-Object -Property SizeGB -Sum | Select-Object -ExpandProperty Sum
$snap |
Where {$_.Created -lt $now.AddDays(-3) -and $_.Created -gt $now.AddDays(-10)} |
Select @{N='VM';E={$_.VM.Name}},
Name, Created,
@{N='SizeGB';E={[math]::Round($_.SizeGB,3)}},
@{N='AllSnapShotSizeGB';E={[math]::Round($totalSnapSizeGB,3)}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Something like this?
$now = Get-Date
Get-VM |
Get-Snapshot |
Where {$_.Created -lt $now.AddDays(-3) -and $_.Created -gt $now.AddDays(-10)}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks man it works fine. but i need to get snapshot more than three days but less than 10 days along with summation of all VM size.
The objects returned by Get-Snapshot contain a property SizeGB, is that what you want?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
nope i want to get vm who have snapshot more than three days but less than 10 days in a table including the snapshot size in GB and all vm snapshot size sum in the same table is it possible?
You mean like this?
$now = Get-Date
$snap = Get-VM | Get-Snapshot
$totalSnapSizeGB = $snap | Measure-Object -Property SizeGB -Sum | Select-Object -ExpandProperty Sum
$snap |
Where {$_.Created -lt $now.AddDays(-3) -and $_.Created -gt $now.AddDays(-10)} |
Select @{N='VM';E={$_.VM.Name}},
Name, Created, SizeGB,
@{N='AllSnapShotSizeGB';E={$totalSnapSizeGB}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Awesome this does work for allsnapshotsize but VM name shows blank
output
My bad, I forgot to fill in the Expression for the VM calculated property.
Corrected above
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
hey luc this script working just fine but it gives a large number of decimal value like 10 to 12 digit for
SizeGB and AllsnapshotsizeGB. how to get it like 3 decimal value. below screenshot for your reference
You can use the [Math]::Round() method
$now = Get-Date
$snap = Get-VM | Get-Snapshot
$totalSnapSizeGB = $snap | Measure-Object -Property SizeGB -Sum | Select-Object -ExpandProperty Sum
$snap |
Where {$_.Created -lt $now.AddDays(-3) -and $_.Created -gt $now.AddDays(-10)} |
Select @{N='VM';E={$_.VM.Name}},
Name, Created,
@{N='SizeGB';E={[math]::Round($_.SizeGB,3)}},
@{N='AllSnapShotSizeGB';E={[math]::Round($totalSnapSizeGB,3)}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks a lot man. this is working fine.