0
0
PowerShellscripting~30 mins

PowerShell on macOS - Mini Project: Build & Apply

Choose your learning style9 modes available
PowerShell on macOS: Basic Script to List and Filter Files
📖 Scenario: You are using PowerShell on your Mac to manage files in a folder. You want to list all files and then filter files by size.
🎯 Goal: Build a PowerShell script that lists files in a folder, sets a size limit, filters files larger than that size, and displays the filtered list.
📋 What You'll Learn
Create a variable with a list of files in the current directory
Create a variable to hold a size limit in bytes
Filter the list of files to only those larger than the size limit
Display the filtered list of files
💡 Why This Matters
🌍 Real World
Managing files on macOS using PowerShell helps automate tasks like cleaning up large files or organizing documents.
💼 Career
PowerShell skills on macOS are useful for system administrators and developers who work in cross-platform environments.
Progress0 / 4 steps
1
Get the list of files in the current directory
Create a variable called files and set it to the list of files in the current directory using Get-ChildItem -File.
PowerShell
Need a hint?

Use Get-ChildItem -File to get only files, not folders.

2
Set a size limit in bytes
Create a variable called sizeLimit and set it to 1000 to represent 1000 bytes.
PowerShell
Need a hint?

Just assign the number 1000 to sizeLimit.

3
Filter files larger than the size limit
Create a variable called largeFiles and set it to the files from files where the Length property is greater than sizeLimit. Use Where-Object with a script block.
PowerShell
Need a hint?

Use Where-Object { $_.Length -gt $sizeLimit } to filter files by size.

4
Display the filtered list of large files
Use Write-Output to display the variable largeFiles.
PowerShell
Need a hint?

Use Write-Output $largeFiles to show the filtered files.