Exception calling "Send" with "1" argument(s): "Failure sending mail."

It looks like there are no built in cmdlets that can output an .evtx file. There’s a Get-WMIObject method that a lot of people reference but that’s not available in Powershell 7.4 so I went looking further and found a post on this same forum with another technique:

They use a .NET class to read the logs and it has an ExportLog method. It relies on some XML filtering to get what you want but that’s fairly well documented out there too.
Try using this block of code in your script:

# Extract each log file listed in $logArray
$EventSession = New-Object System.Diagnostics.Eventing.Reader.EventLogSession
foreach ($log in $logArray) {
    $destination = Join-Path $destinationPath "$env:COMPUTERNAME-$log-$logDate.evtx"
    Write-Host "Extracting the $log file now."
    $EventSession.ExportLog($Log,'LogName',"*[System[(Level=2 or Level=3)]]",$Destination)
}

This creates the EventLogSession object for reading/exporting the logs, then in your existing loop we just replace the use of wevtutil with the ExportLog method with the following arguments

$Log = The path from Windows Event Viewer
‘LogName’ = the path type from Windows Event Viewer
“*[System[(Level=2 or Level=3)]]” = string query where level correpsonds to the Event Level
Level 1 = Critical
Level 2 = Error
Level 3 = Warning
etc…
$Destination = the filepath destination for where to export the filtered log to

I tested this on my machine with Powershell 7.4 and it worked. The resulting combined file size went from 60MB (too big for email) to only 4.5MB.