Hello,
I need help with for PowerCLI script to get list of deleted Snapshots report for older then 3 days
script below but problem is receive blank report but snap shot deleted successfully
Connect-VIServer -Server x.x.x.x-Credential $MyCredential
#This is where the styling for the HTML report is done
$styles = @"
<style>
body { font-family: 'Helvetica Neue', Helvetica, Arial;
font-size: 14px;
line-height: 20px;
font-weight: 400;
color: black;
}
table{
margin: 0 0 40px 0;
width: 100%;
box-shadow: 0 1px 3px rgba(0,0,0,0.2);
display: table;
border-collapse: collapse;
border: 1px solid black;
text-align: left;
}
th {
font-weight: 900;
color: #99ff66;
background: black;
}
td {
border: 0px;
border-bottom: 1px solid black
}
.20 {
width: 20%;
}
.40 {
width: 40%;
}
</style>
"@
#VM Server List
$vmlist = Get-Content C:\Scripts\AUTOSNAP\vmlist.txt
$des = Get-Content C:\Scripts\AUTOSNAP\des.txt
$dc = Get-Datacenter
$VCNAME = $Global:DefaultVIServers
$report = $report = "<!DOCTYPE html><html><head>$Styles<title>VMWare Snapshot Report</title></head><body>"
$report += "<h1>Delete Snapshot Report for $dc $date</h1><table><th>VM Name</th><th>Description</th><th>Date Created</th><th>Deleted By</th><p>Vcenter IP $VCNAME</p><p>Creted By IT TEAM </p>"
$snap = Get-VM $VMlist | Get-Snapshot | Select-Object Description, Created, VM, SizeMB, SizeGB
foreach ($snap in Get-VM $vmlist | Get-Snapshot | Where{$_.Created -lt (Get-Date).AddDays(-3)} | Where{$_.Description -eq 'DAILYSNAP_AUTO_DELETE_IN_3_DAYS'} ) {
$snapevent = Get-VIEvent -Entity $Snap.VM -Types Info -Finish $Snap.Created -MaxSamples 1 | Where-Object {$_.FullFormattedMessage -imatch 'Task: Create virtual machine snapshot'
}
if ($snapevent -ne $null)
{
$sVM = $Snap.VM
$sDesc = $Snap.Description
$sDate = $Snap.Created
$sUser = $snapevent.UserName
if ($sUser -eq "Domain\Username")
{
$report += "<tr style='background-color:MediumSeaGreen; color: MediumSeaGreen;'><td>$sVM</td><td>$sDesc</td><td>$sDate</td><td>$sUser</td></tr>"
} else {
$report += "<tr style='background-color:blue; color: white;'><td>$sVM</td><td>$sDesc</td><td>$sDate</td><td>$sUser</td></tr>"
}
} else {
$sVM = $Snap.VM
$sDesc = $Snap.Description
$sDate = $Snap.Created
$sUser = $snapevent.UserName
if ($sDesc -eq "Please do not delete this snapshot. It is being used by Veeam Backup.")
{
$report += "<tr style='background-color:MediumSeaGreen; color: white;'><td>$sVM</td><td>$sDesc</td><td>$sDate</td><td>$sUser</td></tr>"
} else {
$report += "<tr><td>$sVM</td><td>$sDesc</td><td>$sDate</td><td>$sUser</td></tr>"
}
}
}
$report += "</table>"
foreach($VM in Get-VM $VMlist) {
Get-VM -Name $vmlist | Get-Snapshot | Where-Object{$_.Created -lt (Get-Date).AddDays(-3)} | Where-Object{$_.Description -eq 'DAILYSNAP_AUTO_DELETE_IN_3_DAYS'} | Remove-Snapshot -Confirm:$false
}
Disconnect-VIServer "*" -force -Confirm:$False
$report += "</body></html>"
$report | Out-File "C:\Scripts\AUTOSNAP\Dally-SNAP-Report1.html"
Please help