Highlighted
Enthusiast
Enthusiast

Snapshot report (old only)

Jump to solution

I have a report that currently shows all snapshots running at that point in time, but I am really only needing to see snaphots that are older than X days, how can I add that limitation.

#############################

#         Variables         #

#############################

$date=Get-Date -format "yyyy-MMM-d"

$datetime=Get-Date

$filelocation="\var\www\Snapshots\snapshot-$date.htm"

#############################

#          Content          #

#############################

$report = Get-VM | Get-Snapshot | Where {$_.vm -NotLike "*_replica*"} | Select-Object vm,name,sizeGB,created,powerstate

#############################

# Add Text to the HTML file #

#############################

$report | ConvertTo-Html –title "VMware Snapshot Check " –body "<H1>VMware Snapshot Check</H1>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File $filelocation

ConvertTo-Html –title "VMware Snapshot Check " –body "<H4>Date and time</H4>",$datetime -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation

ConvertTo-Html –title "VMware Snapshot Check " –body "<H4>VM Count</H4>",$report.Count -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation

0 Kudos
1 Solution

Accepted Solutions
Highlighted
User Moderator
User Moderator

You can amend your Where-clause.

The following will only list snapshots older than 7 days.

#############################

#         Variables         #

#############################

$date = Get-Date -format "yyyy-MMM-d"

$datetime = Get-Date

$filelocation = "\var\www\Snapshots\snapshot-$date.htm"


#############################

#          Content          #

#############################

$tgtDate = (Get-Date).AddDays(-7)


$report = Get-VM | Get-Snapshot |

where { $_.vm -NotLike "*_replica*" -and $_.Created -lt $tgtDate } |

Select-Object vm, name, sizeGB, created, powerstate


#############################

# Add Text to the HTML file #

#############################


$report | ConvertTo-Html –title "VMware Snapshot Check " –body "<H1>VMware Snapshot Check</H1>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File $filelocation

ConvertTo-Html –title "VMware Snapshot Check " –body "<H4>Date and time</H4>",$datetime -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation

ConvertTo-Html –title "VMware Snapshot Check " –body "<H4>VM Count</H4>",$report.Count -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation


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

View solution in original post

0 Kudos
1 Reply
Highlighted
User Moderator
User Moderator

You can amend your Where-clause.

The following will only list snapshots older than 7 days.

#############################

#         Variables         #

#############################

$date = Get-Date -format "yyyy-MMM-d"

$datetime = Get-Date

$filelocation = "\var\www\Snapshots\snapshot-$date.htm"


#############################

#          Content          #

#############################

$tgtDate = (Get-Date).AddDays(-7)


$report = Get-VM | Get-Snapshot |

where { $_.vm -NotLike "*_replica*" -and $_.Created -lt $tgtDate } |

Select-Object vm, name, sizeGB, created, powerstate


#############################

# Add Text to the HTML file #

#############################


$report | ConvertTo-Html –title "VMware Snapshot Check " –body "<H1>VMware Snapshot Check</H1>" -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File $filelocation

ConvertTo-Html –title "VMware Snapshot Check " –body "<H4>Date and time</H4>",$datetime -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation

ConvertTo-Html –title "VMware Snapshot Check " –body "<H4>VM Count</H4>",$report.Count -head "<link rel='stylesheet' href='style.css' type='text/css' />" | Out-File -Append $filelocation


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

View solution in original post

0 Kudos