Submitting System Report Generator to Community Scripts
This commit is contained in:
parent
29d71a104c
commit
e71b8546f9
|
@ -714,5 +714,15 @@
|
||||||
"shell": "powershell",
|
"shell": "powershell",
|
||||||
"category": "TRMM (Win):Active Directory",
|
"category": "TRMM (Win):Active Directory",
|
||||||
"default_timeout": "300"
|
"default_timeout": "300"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"guid": "962d3cce-49a2-4f3e-a790-36f62a6799a0",
|
||||||
|
"filename": "Win_Collect_System_Report_And_Email.ps1",
|
||||||
|
"submittedBy": "https://github.com/rfost52",
|
||||||
|
"name": "Collect System Report and Email",
|
||||||
|
"description": "Generates a system report in HTML format, then emails it",
|
||||||
|
"shell": "powershell",
|
||||||
|
"category": "TRMM (Win):Other",
|
||||||
|
"default_timeout": "300"
|
||||||
}
|
}
|
||||||
]
|
]
|
|
@ -9,12 +9,21 @@
|
||||||
Results are sent as a HTML file to C:\Temp and e-mailed based on provided parameters
|
Results are sent as a HTML file to C:\Temp and e-mailed based on provided parameters
|
||||||
|
|
||||||
.EXAMPLE
|
.EXAMPLE
|
||||||
Example is forthcoming
|
Must provide ALL parameter arguments in the following manner (failing to do so will cause the script to exit out prior to creating and sending the report):
|
||||||
|
|
||||||
|
-agentname <enter directly or use the Script Variable {{agent.hostname}}>
|
||||||
|
-file <enter file name with the extension .HTM or .HTML>
|
||||||
|
-fromaddress <sender's email address>
|
||||||
|
-toaddress <recipient's email address>
|
||||||
|
-smtpserver <address of SMTP mail server to be used for sending the report>
|
||||||
|
-password <password associated with a valid mail account to access the mail server via SMTP>
|
||||||
|
-port <587 is the standard port for sending mail over TLS>
|
||||||
|
|
||||||
.NOTES
|
.NOTES
|
||||||
Change Log
|
Change Log
|
||||||
V1.0 Initial release and parameterization
|
V1.0 Initial release and parameterization
|
||||||
V1.1 Check for C:\Temp path prior to generating report
|
V1.1 Check for C:\Temp path prior to generating report
|
||||||
|
V1.2 Parameter checks with exit codes added
|
||||||
|
|
||||||
|
|
||||||
Reference Links:
|
Reference Links:
|
||||||
|
@ -24,6 +33,7 @@
|
||||||
|
|
||||||
|
|
||||||
param(
|
param(
|
||||||
|
$agentname,
|
||||||
$fromaddress,
|
$fromaddress,
|
||||||
$toaddress,
|
$toaddress,
|
||||||
$smtpserver,
|
$smtpserver,
|
||||||
|
@ -32,17 +42,56 @@ param(
|
||||||
$file
|
$file
|
||||||
)
|
)
|
||||||
|
|
||||||
|
#Parameter Checks with exit codes
|
||||||
|
|
||||||
|
if ([string]::IsNullOrEmpty($agentname)){
|
||||||
|
write-host "You must directly enter a hostname or use the TRMM Script Variable {{agent.hostname}} to pass the hostname from the dashboard."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([string]::IsNullOrEmpty($file)){
|
||||||
|
Write-host "You must provide a file name with a .HTM extension."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([string]::IsNullOrEmpty($fromaddress)){
|
||||||
|
Write-host "You must provide a sender's email address."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([string]::IsNullOrEmpty($toaddress)){
|
||||||
|
write-host "You must provide a recipient's email address."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([string]::IsNullOrEmpty($smtpserver)){
|
||||||
|
write-host "You must provide a SMTP server address."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([string]::IsNullOrEmpty($password)){
|
||||||
|
write-host "You must provide a password for the SMTP server"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if ([string]::IsNullOrEmpty($port)){
|
||||||
|
write-host "A valid port number is required to send the report."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
else{
|
||||||
|
|
||||||
$path = "C:\Temp"
|
$path = "C:\Temp"
|
||||||
$destination = "$path\$file"
|
$destination = "$path\$file"
|
||||||
|
|
||||||
|
|
||||||
if(!(Test-Path -Path $path)){
|
if(!(Test-Path -Path $path)){
|
||||||
write-host "Path does not exist. Creating path prior to generating report"
|
write-host "Path does not exist. Creating path prior to generating report."
|
||||||
New-Item -Path "C:\" -Name "Temp" -ItemType "directory"
|
New-Item -Path "C:\" -Name "Temp" -ItemType "directory"
|
||||||
}
|
}
|
||||||
|
|
||||||
else{
|
else{
|
||||||
Write-host "Path alreaedy exists. Generating Report"
|
Write-host "Path alreaedy exists. Attempting to generate report."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -56,7 +105,7 @@ $a = $a + "</style>"
|
||||||
|
|
||||||
#Heading
|
#Heading
|
||||||
|
|
||||||
"<H1 style='color:green;'>System Report For Agent</H1>" | Out-File $destination -Append
|
"<H1 style='color:green;'>System Report For $agentname</H1>" | Out-File $destination -Append
|
||||||
|
|
||||||
#Network Information
|
#Network Information
|
||||||
|
|
||||||
|
@ -89,23 +138,34 @@ Get-PSDrive | Where {$_.Used -ne $null} | Select Name, @{n='Used';e={[float]($_.
|
||||||
|
|
||||||
Get-Printer | Select Name, Type, PortName | ConvertTo-HTML -Head "<H2 style='color:green;'>Printers</H2>" -body $a | Out-file $destination -append
|
Get-Printer | Select Name, Type, PortName | ConvertTo-HTML -Head "<H2 style='color:green;'>Printers</H2>" -body $a | Out-file $destination -append
|
||||||
|
|
||||||
#Send Email
|
|
||||||
|
|
||||||
# $fromaddress = "<insert your email address>"
|
|
||||||
# $toaddress = "<insert your email address>"
|
try {
|
||||||
$Subject = "System Report for Agent"
|
#Send Email
|
||||||
$body = Get-Content $destination
|
|
||||||
# $smtpserver = "<your smtp address>" #for example, smtp.office365.com
|
$Subject = "System Report for $agentname"
|
||||||
# $Password = "<insert your email password>"
|
$body = Get-Content $destination
|
||||||
# $port = <insert smtp port> #for example, 587
|
|
||||||
|
|
||||||
$message = new-object System.Net.Mail.MailMessage
|
$message = new-object System.Net.Mail.MailMessage
|
||||||
$message.IsBodyHTML = $true
|
$message.IsBodyHTML = $true
|
||||||
$message.From = $fromaddress
|
$message.From = $fromaddress
|
||||||
$message.To.Add($toaddress)
|
$message.To.Add($toaddress)
|
||||||
$message.Subject = $Subject
|
$message.Subject = $Subject
|
||||||
$message.body = $body
|
$message.body = $body
|
||||||
$smtp = new-object Net.Mail.SmtpClient($smtpserver, $port)
|
$smtp = new-object Net.Mail.SmtpClient($smtpserver, $port)
|
||||||
$smtp.EnableSsl = $true
|
$smtp.EnableSsl = $true
|
||||||
$smtp.Credentials = New-Object System.Net.NetworkCredential($fromaddress, $Password)
|
$smtp.Credentials = New-Object System.Net.NetworkCredential($fromaddress, $Password)
|
||||||
$smtp.Send($message)
|
$smtp.Send($message)
|
||||||
|
|
||||||
|
write-host "System Report successfully sent via email."
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
catch {
|
||||||
|
write-host "An error occurrd. Please check your parameters, SMTP server name, or credentials and try again."
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
exit $LASTEXITCODE
|
Loading…
Reference in New Issue