0
0
PowerShellscripting~10 mins

Monitoring scripts with email alerts in PowerShell - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to send an email alert using PowerShell's Send-MailMessage cmdlet.

PowerShell
Send-MailMessage -To "admin@example.com" -From "monitor@example.com" -Subject "Alert" -Body "Disk space low" -SmtpServer [1]
Drag options to blanks, or click blank then click option'
Amailserver
Blocalhost
C192.168.1.1
Dsmtp.example.com
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'localhost' when no SMTP server is running locally
Using an IP address that is not the SMTP server
Leaving the SMTP server blank
2fill in blank
medium

Complete the code to check if free disk space on C: drive is less than 10 GB.

PowerShell
$freeSpace = (Get-PSDrive -Name C).Free; if ($freeSpace [1] 10GB) { Write-Output "Low disk space" }
Drag options to blanks, or click blank then click option'
A-lt
B-gt
C-eq
D-ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-gt' which means greater than
Using '-eq' which means equal
Using '-ne' which means not equal
3fill in blank
hard

Fix the error in the script to send an email alert only if disk space is low.

PowerShell
if ($freeSpace [1] 5GB) { Send-MailMessage -To "admin@example.com" -From "monitor@example.com" -Subject "Disk Alert" -Body "Disk space critically low" -SmtpServer "smtp.example.com" }
Drag options to blanks, or click blank then click option'
A-gt
B-lt
C-eq
D-ne
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-gt' which triggers alert when space is more than 5GB
Using '-eq' which triggers alert only if exactly 5GB
Using '-ne' which triggers alert for any value except 5GB
4fill in blank
hard

Fill both blanks to create a hashtable with drive letter as key and free space as value, filtering drives with more than 20GB free.

PowerShell
$drives = Get-PSDrive | Where-Object { $_.Free [1] 20GB } | ForEach-Object { @{ $_.Name = $_.Free [2] } }
Drag options to blanks, or click blank then click option'
A-gt
B-lt
C=
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-lt' instead of '-gt' for filtering
Using '==' instead of '=' for assignment
Confusing comparison and assignment operators
5fill in blank
hard

Fill the blanks to create a script that checks disk space, sends alert if below threshold, and logs the event.

PowerShell
$threshold = 15GB
$freeSpace = (Get-PSDrive -Name D).Free
if ($freeSpace [1] $threshold) {
    Send-MailMessage -To "admin@example.com" -From "monitor@example.com" -Subject "Disk Alert" -Body "Drive D low space" -SmtpServer [2]
    Add-Content -Path "C:\Logs\disk_alert.log" -Value "Drive D low space at $(Get-Date)"
}
else {
    Write-Output "Disk space sufficient"
}
Drag options to blanks, or click blank then click option'
A-lt
Bsmtp.example.com
C-gt
Dlocalhost
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-gt' instead of '-lt' in the condition
Using wrong SMTP server address
Confusing log file path with SMTP server