0
0
PowerShellscripting~20 mins

PowerShell on macOS - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PowerShell macOS Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this PowerShell command on macOS?
Consider this command run in PowerShell on macOS:
Get-ChildItem -Path ~ -File | Where-Object { $_.Length -gt 1000 } | Select-Object -First 1 -Property Name, Length

What does this command output?
PowerShell
Get-ChildItem -Path ~ -File | Where-Object { $_.Length -gt 1000 } | Select-Object -First 1 -Property Name, Length
AAn empty list because no files are returned
BAn error saying 'Where-Object' is not recognized
CAn object showing the Name and Length of the first file in the home directory larger than 1000 bytes
DA list of all files in the home directory regardless of size
Attempts:
2 left
💡 Hint
Think about filtering files by size and selecting only the first match.
📝 Syntax
intermediate
1:30remaining
Which PowerShell syntax correctly sets an environment variable on macOS?
You want to set an environment variable named MY_VAR with value 'hello' in PowerShell on macOS. Which option is correct?
Aenv MY_VAR='hello'
B$env:MY_VAR = 'hello'
Cexport MY_VAR='hello'
Dset MY_VAR=hello
Attempts:
2 left
💡 Hint
PowerShell uses a special variable prefix for environment variables.
🔧 Debug
advanced
2:00remaining
Why does this PowerShell script fail on macOS?
This script is intended to list all running processes and filter those using more than 100 MB of memory:
Get-Process | Where-Object { $_.WorkingSet -gt 100MB }

Why does it fail?
PowerShell
Get-Process | Where-Object { $_.WorkingSet -gt 100MB }
A'100MB' is not a valid number; PowerShell does not recognize 'MB' as a unit, causing a syntax error.
BGet-Process is not available on macOS PowerShell.
CThe property 'WorkingSet' does not exist on process objects on macOS.
DWhere-Object cannot filter numeric properties.
Attempts:
2 left
💡 Hint
Check how PowerShell handles numeric values with units.
🚀 Application
advanced
2:30remaining
How to schedule a PowerShell script to run daily on macOS?
You want to run a PowerShell script located at /Users/username/scripts/backup.ps1 every day at 2 AM on macOS. Which approach is correct?
AUse Windows Task Scheduler to schedule the script
BCreate a cron job with: 0 2 * * * pwsh /Users/username/scripts/backup.ps1
CAdd the script to /etc/init.d to run daily
DUse launchd with a plist file to schedule the script
Attempts:
2 left
💡 Hint
macOS uses launchd for scheduled tasks, not cron by default.
🧠 Conceptual
expert
3:00remaining
What is the main difference when running PowerShell scripts on macOS compared to Windows?
Choose the best explanation for a key difference when running PowerShell scripts on macOS versus Windows.
APowerShell on macOS uses a different shell executable and has limited access to Windows-specific cmdlets and APIs.
BPowerShell scripts run identically on macOS and Windows with no differences.
CPowerShell on macOS cannot run scripts at all, only commands interactively.
DPowerShell on macOS requires scripts to be written in Bash syntax.
Attempts:
2 left
💡 Hint
Think about platform-specific features and cmdlets.