migrate to git.charlotte.sh

This commit is contained in:
Charlotte Croce 2025-04-19 23:42:08 -04:00
commit fbd588721e
412 changed files with 13750 additions and 0 deletions

View file

@ -0,0 +1,74 @@
#10/12/24
function readConfiguration(){
Set-Location "C:\Users\champuser\SYS320\week7"
$configs = (Get-Content -Path ./configuration.txt)
$days = $configs[0]
$time = $configs[1]
return [PSCustomObject]@{
Days = $days
ExecutionTime = $time
}
}
function changeConfiguration(){
$daysBack = Read-Host -Prompt "Number of days for which the logs will be obtained"
if($daysBack -notmatch '^[0-9]+$'){
Write-Host "invalid input. digits only" | Out-String
continue
}
$executionTime = Read-Host -Prompt "Daily execution time of the script"
if($executionTime -inotmatch '^(1?[1-9]):([0-5][0-9])\s(AM|PM)$'){
Write-Host "invalid input. digit:digitdigit am/pm allowed" | Out-String
continue
}
"$daysBack`n$executionTime" | Set-Content ./configuration.txt
Write-Host "Configuration Changed`n" | Out-String
}
#main loop
function configurationMenu(){
clear
$Prompt = "`nPlease choose your operation:`n"
$Prompt += "1 - Show Configuration`n"
$Prompt += "2 - Change Configuration`n"
$Prompt += "3 - Exit`n"
$operation = $true
while($operation){
Write-Host $Prompt | Out-String
$choice = Read-Host
# exit
if($choice -eq 3){
Write-Host "Goodbye" | Out-String
exit
$operation = $false
}
# show configuration
elseif($choice -eq 1){
$config = readConfiguration
$config
}
# change configuration
elseif($choice -eq 2){
changeConfiguration
}
else{
Write-Host "invalid input: 1-3 allowed`n" | Out-String
}
}
}
#configurationMenu

View file

@ -0,0 +1,18 @@
# sends an email to charlotte.croce@mymail.champlain.edu
# with one parameter for the email body
function SendAlertEmail($Body){
$From = "charlotte.croce@mymail.champlain.edu"
$To = "charlotte.croce@mymail.champlain.edu"
$Subject = "Suspicious Activity"
# remove password before publishing to GitHub!
# ...and if you accidentally push with the password visible, just delete the appKey
$Password = "insert-new-appkey-here" | ConvertTo-SecureString -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $From, $Password
Send-MailMessage -From $From -To $To -Subject $Subject -Body $Body -SmtpServer "smtp.gmail.com" `
-Port 587 -UseSsl -Credential $Credential
}
#SendAlertEmail "test email body"

View file

@ -0,0 +1,27 @@
# sends an email to charlotte.croce@mymail.champlain.edu
# with one parameter for the email body
function SendAlertEmail($Body){
$From = "charlotte.croce@mymail.champlain.edu"
$To = "charlotte.croce@mymail.champlain.edu"
$Subject = "Suspicious Activity"
# remove password before publishing to GitHub!
<<<<<<< HEAD
<<<<<<< HEAD
# ...and if you accidentally push with the password visible, just delete the appKey
$Password = "insert-new-appkey-here" | ConvertTo-SecureString -AsPlainText -Force
=======
$Password = "xxxx" | ConvertTo-SecureString -AsPlainText -Force
>>>>>>> 2a39cde6cba8cf89a13018201ce592d875e1409e
=======
# ...and if you accidentally push with the password visible, just delete the appKey
$Password = "insert-new-appkey-here" | ConvertTo-SecureString -AsPlainText -Force
>>>>>>> 25c575397b1c76c4310e671c9a2bd7a2e53bf60a
$Credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $From, $Password
Send-MailMessage -From $From -To $To -Subject $Subject -Body $Body -SmtpServer "smtp.gmail.com" `
-Port 587 -UseSsl -Credential $Credential
}
#SendAlertEmail "test email body"

View file

@ -0,0 +1,45 @@
<# ******************************************************
Functions: Creates a new scheduled task for week7/main.ps1 to run
Input: 1) Time for shceduled task to run
********************************************************* #>
function ChooseTimeToRun($Time){
$scheduledTask = Get-ScheduledTask | Where-Object { $_.TaskName -ilike "mytask" }
if($scheduledTask -ne $null){
Write-Host "The task already exists" | Out-String
DisableAutoRun
}
Write-Host "Creating new task" | Out-String
$action = New-ScheduledTaskAction -Execute "powershell.exe" `
-Argument "-File `"C:\Users\champuser\SYS320\week7\main.ps1`""
$trigger = New-ScheduledTaskTrigger -Daily -At $Time
$principal = New-ScheduledTaskPrincipal -UserId 'champuser' -RunLevel Highest
$settings = New-ScheduledTaskSettingsSet -RunOnlyIfNetworkAvailable -WakeToRun
$task = New-ScheduledTask -Action $action -Principal $principal -Trigger $trigger -Settings $settings
Register-ScheduledTask 'myTask' -InputObject $task
Get-ScheduledTask | Where-Object { $_.TaskName -ilike "myTask" }
}
<# ******************************************************
Functions: if "myTask is running", unregister it
********************************************************* #>
function DisableAutoRun(){
$scheduledTasks = Get-ScheduledTask | Where-Object { $_.TaskName -ilike "myTask" }
if($scheduledTasks -ne $null){
Write-Host "Unregistering the task." | Out-String
Unregister-ScheduledTask -TaskName 'myTask' -Confirm:$false
}
else{
Write-Host "The task is not registered" | Out-String
}
}

View file

@ -0,0 +1,2 @@
90
2:38 PM

View file

@ -0,0 +1,17 @@
. "C:\Users\champuser\SYS320\week6\Event-Logs.ps1"
. "C:\Users\champuser\SYS320\week7\Configuration.ps1"
. "C:\Users\champuser\SYS320\week7\Email.ps1"
. "C:\Users\champuser\SYS320\week7\Scheduler.ps1"
# obtain configuration, from Configurations.ps1
$configuration = readConfiguration
# call atRiskUsers using days obtained from the config file, from Event-logs.ps1
$Failed = getAtRiskUsers $configuration.Days
# sending at risk users as email, from Email.ps1
SendAlertEmail ($Failed | Format-Table | Out-String)
# setting the script to be run daily, from Scheduler.ps1
ChooseTimeToRun($configuration.ExecutionTime)