I'm trying to email the output of a script, but I'm pretty sure I have my syntax all mixed up.
Here what I'd like:
send-mailmessage -from " Daily Check <[email protected]>" -to "Admin <[email protected]>" -subject "Daily Check: Server Times" -body $output -priority High -dno onSuccess, onFailure -smtpServer mail.company.com
$output=
{
ForEach ($server in $servers) {
$time = ([WMI]'').ConvertToDateTime((gwmi win32_operatingsystem -computername $server).LocalDateTime)
$server + ' ' + $time
}
}
$servers = 'SVRADFS365', 'SVRAPP01', 'SVRCAS01', 'SVRCAS02
The original script whose output I want emailed:
$servers = 'server1', 'server2', 'server3', 'server4'
ForEach ($server in $servers) {
$time = ([WMI]'').ConvertToDateTime((gwmi win32_operatingsystem -computername $server).LocalDateTime)
$server + ' ' + $time
}