#The following variables should be changed:
#$file ? should be named with a .htm ending
#$fromaddress
#$toaddress
#$smtpserver
#$Password
#$port
$file = "C:\Temp\Report.htm"
#HTML Styling
$a = ""
#Heading
"
System Report For Agent
" | Out-File $file -Append
#Network Information
Get-WmiObject win32_networkadapterconfiguration -filter "ipenabled = 'True'"|
Select PSComputername, DNSHostName, Description,
@{Name = "IPAddress";Expression =
{[regex]$rx = "(\d{1,3}(\.?)){4}"
$rx.matches($_.IPAddress).Value}},MACAddress | ConvertTo-HTML -Head "Network Information
" -body $a | Out-file $file -Append
#Get Event logs
Get-EventLog -LogName Application -Newest 10 -EntryType Error | Select TimeGenerated, EventID, Source, Message | ConvertTo-HTML -Head "Application Error Event Logs
" -body $a | Out-file $file -Append
Get-EventLog -LogName Application -Newest 10 -EntryType Warning | Select TimeGenerated, EventID, Source, Message | ConvertTo-HTML -Head "Application Warning Event Logs
" -body $a | Out-file $file -Append
Get-EventLog -LogName System -Newest 10 -EntryType Error | Select TimeGenerated, EventID, Source, Message | ConvertTo-HTML -Head "System Error Event Logs
" -body $a | Out-file $file -Append
Get-EventLog -LogName System -Newest 10 -EntryType Warning | Select TimeGenerated, EventID, Source, Message | ConvertTo-HTML -Head "System Warning Event Logs
" -body $a | Out-file $file -Append
#Get Stopped Services
Get-Service | Where {($_.Status) -eq "Stopped"} | Select Status, Name, DisplayName | ConvertTo-HTML -Head "Stopped Services
" -body $a | Out-File $file -Append
#Get Processes and CPU
Get-Process | Select Id, ProcessName, CPU | ConvertTo-HTML -Head "Processes & CPU
" -body $a | Out-File $file -Append
#Get Mapped Drives
Get-PSDrive | Where {$_.Used -ne $null} | Select Name, @{n='Used';e={[float]($_.Used/1GB)}}, @{n='Free';e={[float]($_.Free/1GB)}}, Root| ConvertTo-HTML -Head "Mapped Drives
" -body $a | Out-File $file -Append
#Get Printers
Get-Printer | Select Name, Type, PortName | ConvertTo-HTML -Head "Printers
" -body $a | Out-file $file -append
#Send Email
$fromaddress = ""
$toaddress = ""
$Subject = "System Report for Agent"
$body = Get-Content $file
$smtpserver = "" #for example, smtp.office365.com
$Password = ""
$port = #for example, 587
$message = new-object System.Net.Mail.MailMessage
$message.IsBodyHTML = $true
$message.From = $fromaddress
$message.To.Add($toaddress)
$message.Subject = $Subject
$message.body = $body
$smtp = new-object Net.Mail.SmtpClient($smtpserver, $port)
$smtp.EnableSsl = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential($fromaddress, $Password)
$smtp.Send($message)