0
0
PowerShellscripting~15 mins

Why automation saves time in PowerShell - See It in Action

Choose your learning style9 modes available
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
Need a 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
Need a 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
Need a 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
Need a hint?

Use Write-Output with $( ) to insert variables inside the string.