Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Why automation saves time
📖 Scenario: You work in an office where you need to check the size of several folders every day. Doing this manually takes a lot of time. Automation can help you save time by doing this task automatically.
🎯 Goal: Build a simple PowerShell script that lists folder names and their sizes automatically, showing how automation saves time.
📋 What You'll Learn
Create a list of folder names with their sizes in megabytes
Set a size threshold to filter folders larger than this size
Use a loop to select folders larger than the threshold
Print the filtered folder names and sizes
💡 Why This Matters
🌍 Real World
Automating folder size checks helps office workers save time by avoiding manual checking every day.
💼 Career
Many IT and office jobs require automating repetitive tasks to improve efficiency and reduce errors.
Progress0 / 4 steps
1
Create the folder size data
Create a variable called folders that holds a list of hashtables. Each hashtable should have Name and SizeMB keys with these exact values: Name = 'Docs', SizeMB = 120, Name = 'Photos', SizeMB = 80, Name = 'Videos', SizeMB = 300.
PowerShell
Hint
Use @() to create a list and @{} to create each folder's data.
2
Set the size threshold
Create a variable called sizeThreshold and set it to 100 to filter folders larger than 100 MB.
PowerShell
Hint
Just create a variable and assign the number 100.
3
Filter folders larger than the threshold
Create a variable called largeFolders that uses a foreach loop with variable folder to go through $folders. Inside the loop, add folders to largeFolders only if $folder.SizeMB is greater than $sizeThreshold.
PowerShell
Hint
Start with an empty list, then add folders inside the loop if they are bigger than the threshold.
4
Print the filtered folders
Use a foreach loop with variable folder to go through $largeFolders and print each folder's name and size in this format: Folder: Docs, Size: 120 MB.
PowerShell
Hint
Use Write-Output with $( ) to insert variables inside the string.
Practice
(1/5)
1. Why does automation save time in PowerShell scripting?
easy
A. It deletes all files to save space
B. It runs repetitive tasks automatically without manual effort
C. It requires more manual input to control tasks
D. It makes scripts run slower to avoid errors
Solution
Step 1: Understand automation purpose
Automation is designed to perform repetitive tasks without needing manual work each time.
Step 2: Relate to PowerShell scripting
PowerShell scripts automate commands, so tasks run faster and with less effort.
Final Answer:
It runs repetitive tasks automatically without manual effort -> Option B
Quick Check:
Automation saves time = It runs repetitive tasks automatically without manual effort [OK]
Hint: Automation means less manual work, more done fast [OK]
Common Mistakes:
Thinking automation slows down tasks
Believing automation needs more manual input
Confusing automation with deleting files
2. Which PowerShell command syntax correctly automates listing files in a folder?
easy
A. Get-ChildItem -Path C:\Folder
B. List-Files C:\Folder
C. Show-Directory C:\Folder
D. Get-Files -Folder C:\Folder
Solution
Step 1: Identify correct PowerShell command
The standard command to list files is Get-ChildItem with a -Path parameter.
Step 2: Check options for valid syntax
Only Get-ChildItem -Path C:\Folder uses the correct command and parameter format.