Bird
Raised Fist0
PowerShellscripting~20 mins

PowerShell vs Bash vs CMD comparison - Practice Questions

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Shell Scripting Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
PowerShell vs Bash: Command Output Differences
What is the output of this PowerShell command compared to its Bash equivalent?

PowerShell: Get-ChildItem | Where-Object { $_.Length -gt 1000 }
Bash: ls -l | awk '$5 > 1000'

Assuming both commands run in a directory with files of various sizes, what does the PowerShell command output?
PowerShell
Get-ChildItem | Where-Object { $_.Length -gt 1000 }
ALists only directories larger than 1000 bytes
BLists all files and directories regardless of size
CLists files with size greater than 1000 bytes, including directories with Length property
DLists files with size less than 1000 bytes
Attempts:
2 left
💡 Hint
Think about how PowerShell objects have properties like Length and how Where-Object filters them.
📝 Syntax
intermediate
1:30remaining
Syntax Differences: Variable Assignment
Which of the following is the correct way to assign a variable in PowerShell compared to Bash and CMD?
A$var = "Hello"
Bvar = "Hello"
Cset var=Hello
Dlet var = "Hello"
Attempts:
2 left
💡 Hint
PowerShell uses $ before variable names.
🔧 Debug
advanced
2:00remaining
Debugging a PowerShell Pipeline vs Bash Pipeline
Given this PowerShell pipeline:
Get-Process | Where-Object { $_.CPU -gt 100 }
and this Bash pipeline:
ps aux | awk '$3 > 100'
Which statement about their behavior is true?
ABoth commands will produce syntax errors
BPowerShell filters processes with CPU time greater than 100 seconds; Bash filters processes with CPU usage percentage greater than 100%
CPowerShell filters processes with CPU usage percentage over 100%; Bash filters CPU time over 100 seconds
DBoth filter processes with CPU usage over 100%
Attempts:
2 left
💡 Hint
Consider what the CPU property in PowerShell and the third column in ps aux represent.
🚀 Application
advanced
2:30remaining
Automating File Backup: PowerShell vs CMD
You want to copy all .txt files from C:\Data to D:\Backup preserving directory structure.
Which PowerShell command correctly does this compared to CMD's xcopy C:\Data D:\Backup /S /I /Y?
ACopy-Item -Path C:\Data\*.txt -Destination D:\Backup -Recurse -Container
BCopy-Item -Path C:\Data\*.txt -Destination D:\Backup -Recurse -Force
CCopy-Item -Path C:\Data\*.txt -Destination D:\Backup -Recurse
DCopy-Item -Path C:\Data\*.txt -Destination D:\Backup -Force
Attempts:
2 left
💡 Hint
Preserving directory structure requires the -Container parameter in PowerShell.
🧠 Conceptual
expert
3:00remaining
Understanding Object vs Text Pipelines
PowerShell pipelines pass objects between commands, while Bash and CMD pipelines pass text streams.
What is a key advantage of PowerShell's object pipeline over text pipelines?
AIt only works on Windows, so it is more secure
BIt makes scripts run faster because objects are smaller than text
CIt requires less memory because objects are compressed
DIt allows commands to access properties and methods directly, enabling more precise and reliable automation
Attempts:
2 left
💡 Hint
Think about how objects carry structured data compared to plain text.

Practice

(1/5)
1. Which shell is object-based and primarily designed for Windows automation?
easy
A. CMD
B. Bash
C. PowerShell
D. Zsh

Solution

  1. Step 1: Understand shell types

    PowerShell is known for handling objects, unlike Bash and CMD which handle text.
  2. Step 2: Identify platform focus

    PowerShell is designed mainly for Windows automation, while Bash is common on Linux/macOS and CMD is basic Windows shell.
  3. Final Answer:

    PowerShell -> Option C
  4. Quick Check:

    Object-based Windows shell = PowerShell [OK]
Hint: PowerShell = objects + Windows automation [OK]
Common Mistakes:
  • Confusing Bash as object-based
  • Thinking CMD is object-based
  • Selecting shells not related to Windows
2. Which of the following is the correct way to list files in PowerShell?
easy
A. ls -l
B. listfiles
C. dir /w
D. Get-ChildItem

Solution

  1. Step 1: Recall PowerShell commands

    PowerShell uses cmdlets like Get-ChildItem to list files.
  2. Step 2: Compare with other shells

    ls -l is Bash/Linux syntax, dir /w is CMD syntax, listfiles is invalid.
  3. Final Answer:

    Get-ChildItem -> Option D
  4. Quick Check:

    PowerShell file list = Get-ChildItem [OK]
Hint: PowerShell cmdlets start with Get- or Set- [OK]
Common Mistakes:
  • Using Bash command ls -l in PowerShell
  • Using CMD dir /w in PowerShell
  • Typing invalid commands like listfiles
3. What will be the output of this PowerShell command?
Get-Process | Where-Object { $_.CPU -gt 100 }
medium
A. Lists all processes with CPU usage less than 100 seconds
B. Lists all processes with CPU usage greater than 100 seconds
C. Shows an error because CPU property does not exist
D. Lists all processes regardless of CPU usage

Solution

  1. Step 1: Understand Get-Process output

    Get-Process returns process objects with a CPU property showing CPU time in seconds.
  2. Step 2: Analyze Where-Object filter

    The filter $_.CPU -gt 100 selects processes with CPU time greater than 100 seconds.
  3. Final Answer:

    Lists all processes with CPU usage greater than 100 seconds -> Option B
  4. Quick Check:

    Filter CPU > 100 seconds = Lists all processes with CPU usage greater than 100 seconds [OK]
Hint: Where-Object filters objects by property conditions [OK]
Common Mistakes:
  • Confusing greater than (gt) with less than
  • Assuming CPU property is missing
  • Thinking it lists all processes without filtering
4. Identify the error in this PowerShell command that tries to list files:
ls -l | grep ".txt"
medium
A. PowerShell does not support ls -l syntax
B. grep is not a native PowerShell command
C. Quotes around .txt should be single quotes
D. The pipe symbol | is invalid in PowerShell

Solution

  1. Step 1: Check command compatibility

    PowerShell supports ls alias but not with -l option; it uses Get-ChildItem instead.
  2. Step 2: Identify grep usage

    grep is a Linux command, not native in PowerShell; PowerShell uses Where-Object or Select-String.
  3. Final Answer:

    PowerShell does not support ls -l syntax -> Option A
  4. Quick Check:

    ls -l syntax unsupported = PowerShell does not support ls -l syntax [OK]
Hint: PowerShell ls alias lacks Bash -l flag [OK]
Common Mistakes:
  • Assuming ls -l works fully in PowerShell
  • Thinking pipe | is invalid
  • Believing quote style causes error here
5. You want to write a script that works on Windows and Linux to list files. Which approach is best?
hard
A. Write a PowerShell script using Get-ChildItem and run PowerShell Core on both OS
B. Write a Bash script using ls and run it only on Linux
C. Write a CMD batch file using dir and run it on Windows only
D. Write separate scripts for each OS and manually switch

Solution

  1. Step 1: Consider cross-platform support

    PowerShell Core (PowerShell 7+) runs on Windows and Linux, supporting Get-ChildItem on both.
  2. Step 2: Evaluate other options

    Bash scripts work only on Linux/macOS; CMD batch files only on Windows; separate scripts add complexity.
  3. Final Answer:

    Write a PowerShell script using Get-ChildItem and run PowerShell Core on both OS -> Option A
  4. Quick Check:

    Cross-platform scripting = PowerShell Core + Get-ChildItem [OK]
Hint: PowerShell Core runs cross-platform, unlike CMD or Bash alone [OK]
Common Mistakes:
  • Assuming Bash works on Windows by default
  • Thinking CMD scripts run on Linux
  • Ignoring cross-platform PowerShell Core availability
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard