Lab 8: Intro to Powershell - squatchulator/Tech-Journal GitHub Wiki

searchlogs.ps1

# Storyline: Review the Security Event Log

# Directory to save files 
$myDir = "C:\Users\Miles\Desktop\"
# List all the available Windows Event Logs

Get-EventLog -list

# Create a prompt to allow user to select the Log to view
$readLog = Read-host -Prompt "Please select a log to review from the list above"

# Create a prompt to allow user to search for a phrase in the selected Log
$searchTerm = Read-Host -Prompt "Please enter a phrase you would like to search"

# Print the results for the log
Get-EventLog -LogName $readLog -Newest 40 | where {$_.Message -ilike "*$searchTerm*" } | export-csv -NoTypeInformation `
-Path "$myDir\securityLogs.csv"

# Task: Create a prompt that allows the user to specify a keyword or phrase to search on.
# Find  a string from your event logs to search on

sendemail.ps1

# Storyline: Send an email.

# Body of the email
# Variables can have underscores or any alphanumeric value
$msg = "Hello There"

# Echo to the screen
write-host -BackgroundColor DarkRed -ForegroundColor DarkBlue $msg

# Email From Address
$email = "[email protected]"

# To Address
$toEmail = "deployer@csi-web"

# Send the email
Send-MailMessage -From $email -to $toEmail -Subject "A Greeting" -body $msg -SmtpServer 192.168.6.71