On the Creator, that's the reason I asked for the presence of a vCenter.
A vCenter normally keeps Events and Tasks for up to a year, on an ESXi node, this is much more limited (a couple of days at best).
To send the result via email, you could do something like this.
I used a very simple style for the report, you can find many more elaborate styles on the Internet.
$esxNames='esx1','esx2'
$user='root'
$pswd='secret_password!'
$Header=@"
<style>
TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}
TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}
</style>
"@
$now=Get-Date
$report=foreach($esxNamein$esxNames){
$srv=Connect-VIServer-Server$esxName-User$user-Password$pswd
Get-VM-Server$srv|Get-Snapshot|
Where{(New-TimeSpan-Start$_.Created -End$now).TotalDays -ge7} |
Select @{N='VMName';E={$_.VM.Name}},
@{N='VMState';E={$_.vm.PowerState}},
@{N='VMHost IP Details';E={(Get-VMHostNetworkAdapter-VMKernel-VMHost$_.vm.VMHost).IP -join'|'}},
@{N='ProvisionedSpaceGB';E={[math]::Round($_.VM.ProvisionedSpaceGB,2)}},
@{N='UsedSpaceGB';E={[math]::Round($_.VM.UsedSpaceGB,2)}},
@{N='Datastore';E={($_.vm |Get-Datastore).Name -join'|'}},
@{N='Datastore Capacity';E={($_.vm |Get-Datastore).CapacityGB -join'|'}},
@{N='SnapshotName';E={$_.Name}},
@{N='SnapshotDate';E={$_.Created}},
@{N='SnapshotSizeGB';E={[math]::Round($_.SizeGB,2)}},
@{N='SnapshotCreator';E={
Get-VIEvent-Start$_.Created.AddMinutes(-1) -Finish$_.Created.AddMinutes(1) |
where{$_-is[VMware.Vim.TaskEvent]-and$_.Info.DescriptionId -eq'VirtualMachine.createSnapshot'} |
select-Last1-ExpandPropertyUserName}}
Disconnect-VIServer-Server$esxName-Confirm:$false
}
$sMail= @{
Body =$report|ConvertTo-Html-Head$Header|Out-String
BodyAsHtml =$true
To ='me@domain.com'
From ='you@domain.com'
Subject ='Snapshot report'
SmtpServer ='mail.domain.com'
}
Send-MailMessage@sMail