VMware Cloud Community
mahady_hassan
Enthusiast
Enthusiast
Jump to solution

Snapshot more than three days but less than 10 days

How can i get snapshot age more than 3 days but less than 10 days

Reply
0 Kudos
3 Solutions

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

LucD
Leadership
Leadership
Jump to solution

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

View solution in original post

Reply
0 Kudos
10 Replies
LucD
Leadership
Leadership
Jump to solution

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

mahady_hassan
Enthusiast
Enthusiast
Jump to solution

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.

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

The objects returned by Get-Snapshot contain a property SizeGB, is that what you want?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

Reply
0 Kudos
mahady_hassan
Enthusiast
Enthusiast
Jump to solution

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?

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

mahady_hassan
Enthusiast
Enthusiast
Jump to solution

Awesome this does work for allsnapshotsize but VM name shows blank 

output

mahady_hassan_0-1678358224014.png

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

mahady_hassan
Enthusiast
Enthusiast
Jump to solution

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

 

mahady_hassan_0-1678361614343.png

 

 

Reply
0 Kudos
LucD
Leadership
Leadership
Jump to solution

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

Reply
0 Kudos
mahady_hassan
Enthusiast
Enthusiast
Jump to solution

Thanks a lot man. this is working fine.

Reply
0 Kudos