You can try this:
# Adding PowerCLI Snapin if(!(get-pssnapin | where {$_.name -eq "vmware.vimautomation.core"})) { try { add-pssnapin VMware.VimAutomation.Core| out...
See more...
You can try this:
# Adding PowerCLI Snapin if(!(get-pssnapin | where {$_.name -eq "vmware.vimautomation.core"})) { try { add-pssnapin VMware.VimAutomation.Core| out-null } catch { throw "Could not load PowerCLI snapin" } }
$VIServer = "vcenter1","vcenter2" $Report = @() foreach($VCserver in $VIserver){ $currentVC = Connect-VIServer -Server $VCserver -Protocol https -User administrator -Password Pass@123 $Header = @" <style> TABLE {border-width: 1px;border-style: solid;border-color: black;border-collapse: collapse;} TH {border-width: 1px;padding: 3px;border-style: solid;border-color: black;background-color: #6495ED;} TD {border-width: 1px;padding: 3px;border-style: solid;border-color: black;} .odd { background-color:#ffffff; } .even { background-color:#dddddd; } </style> <title>Snapshot Report - $VcServer</title> "@ $a = Get-VM -Server $currentVC | Get-Snapshot | Select VM,@{N="VCname";E={$currentVC.Name}},Name,Description,Created,SizeMB,SizeGB If (-not $a){ $a = New-Object PSObject -Property @{ VCname = "No snapshots found on any VM's controlled by $($currentVC.Name)" VM = "" Name = "" Description = "" SizeGB = "" Created = "" } } Disconnect-VIServer $currentVC -Force -Confirm:$false $Report += $a } $Report = $report | Select VCname,VM,Name,Description,SizeGB,Created | ConvertTo-Html -Head $Header -PreContent "<p><h2>Snapshot Report</h2></p><br>" $Report | Out-File "C:\VM-operations\dailyreport\SnapShotReport.html"