Function smtpMessage($smtpTo, $smtpJob, $smtpBody,$smtpAttch) { $pcDomain = (Get-WmiObject Win32_ComputerSystem).Domain $emailDevice = "$env:COMPUTERNAME" + '.' + "$pcDomain" #Fucntion variables. $emailSmtpServer = "mail.aeroinc.net" $emailSmtpServerPort = "587" $emailSmtpUser = "scripts@aeroinc.net" $emailSmtpPass = "Aisnet@3387" $emailMessage = New-Object System.Net.Mail.MailMessage $emailMessage.From = "scripts@aeroinc.net" $emailMessage.To.Add( "$smtpTo" ) $emailMessage.Subject = " $emailDevice - $smtpJob" $emailMessage.IsBodyHtml = $true $emailMessage.Body = @"
$smtpBody
"@ # $emailMessage.Attachments.Add($smtpAttch) #Action. $SMTPClient = New-Object System.Net.Mail.SmtpClient( $emailSmtpServer , $emailSmtpServerPort ) $SMTPClient.Credentials = New-Object System.Net.NetworkCredential( $emailSmtpUser , $emailSmtpPass ); $SMTPClient.Send( $emailMessage ) $emailMessage.Dispose(); } #Slow script execution $slow = Test-Connection 216.82.160.254 -count 2 $adminEmail = "cms@aerocomputing.com" $adminPhone = "8159905729@email.uscc.net" #Create log directories if not present. $kasRoot = "C:\kworking" $logRoot = "C:\kworking\logs" if(!(Test-Path $kasRoot)){ New-Item -ItemType "directory" -Path "c:\kworking\" } if(!(Test-Path $logRoot)){ New-Item -ItemType "directory" -Path "c:\kworking\logs" } $time = (get-date).AddMinutes(-1) $date = get-date -f hh-mm-tt-MM-dd-yyyy $log = "C:\kworking\logs\logon-$date.html" Add-Content "$log" "Time | Type | Username | Process | IP |
$($i.TimeCreated) | $($i.properties[8].Value) | $who | $($i.properties[17].Value) | $($i.properties[18].Value) |