0
0
PowerShellscripting~30 mins

Scheduled scripts with Task Scheduler in PowerShell - Mini Project: Build & Apply

Choose your learning style9 modes available
Scheduled scripts with Task Scheduler
📖 Scenario: You work in an office where you need to run a PowerShell script every day to check disk space and save the report. Instead of running it manually, you want to automate this using Windows Task Scheduler.
🎯 Goal: Build a PowerShell script that checks disk space on drive C: and saves the output to a file. Then, prepare a Task Scheduler command to run this script daily.
📋 What You'll Learn
Create a PowerShell script variable with disk space check command
Add a variable for the output file path
Write the command to save disk space info to the file
Show the Task Scheduler command to schedule the script daily
💡 Why This Matters
🌍 Real World
Automating routine system checks saves time and avoids manual errors. Scheduled scripts help keep systems healthy without daily manual work.
💼 Career
System administrators and IT support staff often use Task Scheduler and PowerShell scripts to automate maintenance tasks.
Progress0 / 4 steps
1
Create disk space check command
Create a variable called diskCheck that stores the PowerShell command Get-PSDrive -Name C to check disk space on drive C.
PowerShell
Need a hint?

Use double quotes to store the command as a string in the variable diskCheck.

2
Add output file path variable
Create a variable called outputFile and set it to the string "C:\\Reports\\DiskSpaceReport.txt" which will store the disk space report.
PowerShell
Need a hint?

Remember to escape backslashes in the file path by doubling them.

3
Write disk space info to file
Use the Invoke-Expression cmdlet with diskCheck and pipe the output to Out-File using the outputFile variable to save the disk space info to the file.
PowerShell
Need a hint?

Use Invoke-Expression $diskCheck to run the command stored in the variable, then pipe it to Out-File with the path from outputFile.

4
Show Task Scheduler command
Write a PowerShell Write-Output statement that prints the exact command to create a daily scheduled task named DiskSpaceCheck running the script C:\\Scripts\\DiskSpaceCheck.ps1 at 9 AM every day using schtasks.exe.
PowerShell
Need a hint?

Use Write-Output to print the full schtasks command with the correct options for daily scheduling at 9 AM.