Zombie
###########################vCenter Server Snapshots Report #################################
############################## Created By Shobhit Mathur ###################################
############################## MAR - Modify As Required ####################################
$VIServers= "xxx" ###MAR###
$reportFile = Get-Date -UFormat "E:\Sho\Reports\$VIServers-Cluster_Report-%Y-%b-%d @ %I-%M%p.html"
$today = get-Date
$Sho=@"
<style>
TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;Font-Size: 8pt;Font-Family: Tahoma, sans-serif;}
TH {border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color: #edbc64;}
TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
</style>
"@
If (-not (Get-PSSnapin VMware.VimAutomation.Core))
{ Try { Add-PSSnapin VMware.VimAutomation.Core -ErrorAction Stop }
Catch { Write-Host "Unable to load PowerCLI, is it installed?" -ForegroundColor Red; Break }
}
Add-PSsnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
foreach($viserver in $VIServers)
{
Connect-VIServer $VIServers -User xxx -Password xxx ###MAR###
}
$Sho1 =@()
$arrUsedDisks = Get-View -ViewType VirtualMachine | % {$_.Layout} | % {$_.Disk} | % {$_.DiskFile}
$arrDS = Get-Datastore | Sort-Object -property Name
foreach ($strDatastore in $arrDS) {
Write-Host "Checking" $strDatastore.Name "..."
$ds = Get-Datastore -Name $strDatastore.Name | % {Get-View $_.Id}
$fileQueryFlags = New-Object VMware.Vim.FileQueryFlags
$fileQueryFlags.FileSize = $true
$fileQueryFlags.FileType = $true
$fileQueryFlags.Modification = $true
$searchSpec = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec
$searchSpec.details = $fileQueryFlags
$searchSpec.matchPattern = "*.vmdk"
$searchSpec.sortFoldersFirst = $true
$dsBrowser = Get-View $ds.browser
$rootPath = "[" + $ds.Name + "]"
$searchResult = $dsBrowser.SearchDatastoreSubFolders($rootPath, $searchSpec)
foreach ($folder in $searchResult)
{
foreach ($fileResult in $folder.File)
{
if ($fileResult.Path)
{
if (-not ($fileResult.Path.contains("ctk.vmdk"))) #Remove Change Tracking Files
{
if (-not ($arrUsedDisks -contains ($folder.FolderPath.trim('/') + '/' + $fileResult.Path)))
{
$row = "" | Select DS, Path, File, SizeGB, ModDate
$row.DS = $strDatastore.Name
$row.Path = $folder.FolderPath
$row.File = $fileResult.Path
$row.SizeGB = [Math]::Round($fileResult.FileSize/1GB,0)
$row.ModDate = $fileResult.Modification
$Sho1 += $row
}
}
}
}
}
}
$Sho += $Sho1 | ConvertTo-Html -Fragment
$Sho2 = $Sho1 | Measure-Object -Property SizeGB -Sum | select -ExpandProperty Sum
$From = "xxx" ###MAR###
$To = "xxx" ###MAR###
$Cc = "xxx" ###MAR###
$BCC = "xxx" ###MAR###
$Subject = "Zombie Files of xxx" ###MAR###
$Body1 = "<p><h4>
A Report of Zombie-Files for xxx as on $today.<br> ###MAR###
</h4></p>" #| Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd
$Body3 = $Body2 = "<p> <br>Total Size of all Zombie Files Combined = $Sho2 GB </p><br>" #| Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd
$Body2 = "<p> <br><br>This is script generated report, hence for any discrapancies please contact 'xxx'. ###MAR###<br><br>
Best Regards<br>
Sho</p><br>" #| Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd
$HTMLBody = $Body1 +$Body3 + $Sho + $Body3+ $Body2
$SMTPServer = "xxx" ###MAR###
$SMTPPort = "25" ###MAR###
Send-MailMessage -From $From -to $To -cc $Cc -Bcc $BCC -Subject $Subject -BodyAsHTML -body $HTMLBody -SmtpServer $SMTPServer
Disconnect-VIServer $VIServers -Force -Confirm:$false
###########################vCenter Server Snapshots Report #################################
############################## Created By Shobhit Mathur ###################################
############################## MAR - Modify As Required ####################################
$VIServers= "xxx" ###MAR###
$reportFile = Get-Date -UFormat "E:\Sho\Reports\$VIServers-Cluster_Report-%Y-%b-%d @ %I-%M%p.html"
$today = get-Date
$Sho=@"
<style>
TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;Font-Size: 8pt;Font-Family: Tahoma, sans-serif;}
TH {border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color: #edbc64;}
TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;}
</style>
"@
If (-not (Get-PSSnapin VMware.VimAutomation.Core))
{ Try { Add-PSSnapin VMware.VimAutomation.Core -ErrorAction Stop }
Catch { Write-Host "Unable to load PowerCLI, is it installed?" -ForegroundColor Red; Break }
}
Add-PSsnapin VMware.VimAutomation.Core -ErrorAction SilentlyContinue
foreach($viserver in $VIServers)
{
Connect-VIServer $VIServers -User xxx -Password xxx ###MAR###
}
$Sho1 =@()
$arrUsedDisks = Get-View -ViewType VirtualMachine | % {$_.Layout} | % {$_.Disk} | % {$_.DiskFile}
$arrDS = Get-Datastore | Sort-Object -property Name
foreach ($strDatastore in $arrDS) {
Write-Host "Checking" $strDatastore.Name "..."
$ds = Get-Datastore -Name $strDatastore.Name | % {Get-View $_.Id}
$fileQueryFlags = New-Object VMware.Vim.FileQueryFlags
$fileQueryFlags.FileSize = $true
$fileQueryFlags.FileType = $true
$fileQueryFlags.Modification = $true
$searchSpec = New-Object VMware.Vim.HostDatastoreBrowserSearchSpec
$searchSpec.details = $fileQueryFlags
$searchSpec.matchPattern = "*.vmdk"
$searchSpec.sortFoldersFirst = $true
$dsBrowser = Get-View $ds.browser
$rootPath = "[" + $ds.Name + "]"
$searchResult = $dsBrowser.SearchDatastoreSubFolders($rootPath, $searchSpec)
foreach ($folder in $searchResult)
{
foreach ($fileResult in $folder.File)
{
if ($fileResult.Path)
{
if (-not ($fileResult.Path.contains("ctk.vmdk"))) #Remove Change Tracking Files
{
if (-not ($arrUsedDisks -contains ($folder.FolderPath.trim('/') + '/' + $fileResult.Path)))
{
$row = "" | Select DS, Path, File, SizeGB, ModDate
$row.DS = $strDatastore.Name
$row.Path = $folder.FolderPath
$row.File = $fileResult.Path
$row.SizeGB = [Math]::Round($fileResult.FileSize/1GB,0)
$row.ModDate = $fileResult.Modification
$Sho1 += $row
}
}
}
}
}
}
$Sho += $Sho1 | ConvertTo-Html -Fragment
$Sho2 = $Sho1 | Measure-Object -Property SizeGB -Sum | select -ExpandProperty Sum
$From = "xxx" ###MAR###
$To = "xxx" ###MAR###
$Cc = "xxx" ###MAR###
$BCC = "xxx" ###MAR###
$Subject = "Zombie Files of xxx" ###MAR###
$Body1 = "<p><h4>
A Report of Zombie-Files for xxx as on $today.<br> ###MAR###
</h4></p>" #| Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd
$Body3 = $Body2 = "<p> <br>Total Size of all Zombie Files Combined = $Sho2 GB </p><br>" #| Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd
$Body2 = "<p> <br><br>This is script generated report, hence for any discrapancies please contact 'xxx'. ###MAR###<br><br>
Best Regards<br>
Sho</p><br>" #| Set-AlternatingRows -CSSEvenClass even -CSSOddClass odd
$HTMLBody = $Body1 +$Body3 + $Sho + $Body3+ $Body2
$SMTPServer = "xxx" ###MAR###
$SMTPPort = "25" ###MAR###
Send-MailMessage -From $From -to $To -cc $Cc -Bcc $BCC -Subject $Subject -BodyAsHTML -body $HTMLBody -SmtpServer $SMTPServer
Disconnect-VIServer $VIServers -Force -Confirm:$false
No comments:
Post a Comment