Bird
Raised Fist0
PowerShellscripting~20 mins

Why cmdlets are the building blocks in PowerShell - Challenge Your Understanding

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Cmdlet Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why are cmdlets considered the building blocks in PowerShell?
Choose the best explanation for why cmdlets are called the building blocks of PowerShell.
ACmdlets are small, single-function commands that can be combined to perform complex tasks.
BCmdlets are graphical tools used to design PowerShell scripts visually.
CCmdlets are large programs that replace the need for scripting in PowerShell.
DCmdlets are only used for managing files and cannot be combined.
Attempts:
2 left
💡 Hint
Think about how small commands can be combined to do bigger jobs.
💻 Command Output
intermediate
2:00remaining
Output of a simple cmdlet pipeline
What is the output of this PowerShell command? Get-Process | Where-Object {$_.CPU -gt 100} | Select-Object -Property Name, CPU
PowerShell
Get-Process | Where-Object {$_.CPU -gt 100} | Select-Object -Property Name, CPU
ANo output because the command is incomplete.
BAn error saying 'CPU property not found'.
CA list of all processes without filtering.
DA list of process names and their CPU usage where CPU is greater than 100.
Attempts:
2 left
💡 Hint
Look at how the pipeline filters and selects properties.
📝 Syntax
advanced
1:30remaining
Identify the correct syntax for creating a custom cmdlet function
Which option shows the correct syntax to define a simple PowerShell function that acts like a cmdlet?
Adef Get-Greeting(Name): return "Hello, Name!"
Bfunction Get-Greeting { param($Name) "Hello, $Name!" }
Cfunction Get-Greeting($Name) { echo "Hello, $Name!" }
Dfunc Get-Greeting { param Name; Write-Output "Hello, Name!" }
Attempts:
2 left
💡 Hint
PowerShell functions use the 'function' keyword and 'param' block.
🔧 Debug
advanced
1:30remaining
Why does this cmdlet pipeline fail?
This PowerShell command fails with an error. What is the cause? Get-Service | Where-Object {$_.Status = 'Running'}
PowerShell
Get-Service | Where-Object {$_.Status = 'Running'}
AGet-Service does not return objects with a Status property.
BWhere-Object cannot be used in pipelines.
CThe '=' operator is used instead of '-eq' for comparison.
DThe command is missing a closing parenthesis.
Attempts:
2 left
💡 Hint
Check the operator used inside the script block for comparison.
🚀 Application
expert
2:30remaining
How many cmdlets are involved in this script?
Consider this PowerShell script: $files = Get-ChildItem -Path C:\Logs -Filter *.log $recent = $files | Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-7) } $recent | Sort-Object LastWriteTime | Select-Object -First 5 | ForEach-Object { Write-Output $_.Name } How many distinct cmdlets are used in this script?
PowerShell
$files = Get-ChildItem -Path C:\Logs -Filter *.log
$recent = $files | Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-7) }
$recent | Sort-Object LastWriteTime | Select-Object -First 5 | ForEach-Object { Write-Output $_.Name }
A7
B6
C5
D4
Attempts:
2 left
💡 Hint
Count each unique cmdlet name used in the script.

Practice

(1/5)
1. What is a key reason cmdlets are considered the building blocks in PowerShell scripting?
easy
A. They replace the need for variables in scripts.
B. They are graphical tools for designing scripts.
C. They perform a single, specific task very well.
D. They automatically fix errors in scripts.

Solution

  1. Step 1: Understand cmdlet purpose

    Cmdlets are designed to do one task clearly and efficiently.
  2. Step 2: Recognize their role in scripting

    This single-task focus makes them reliable building blocks for automation.
  3. Final Answer:

    They perform a single, specific task very well. -> Option C
  4. Quick Check:

    Cmdlets = single task focus [OK]
Hint: Cmdlets do one job well, like tools in a toolbox [OK]
Common Mistakes:
  • Thinking cmdlets are graphical tools
  • Believing cmdlets fix script errors automatically
  • Assuming cmdlets replace variables
2. Which of the following is the correct syntax for a PowerShell cmdlet?
easy
A. Get-Process
B. process-get
C. GetProcess
D. Get_Process

Solution

  1. Step 1: Recall cmdlet naming style

    Cmdlets use a verb-noun format separated by a dash.
  2. Step 2: Match options to format

    Only 'Get-Process' follows verb-noun with dash correctly.
  3. Final Answer:

    Get-Process -> Option A
  4. Quick Check:

    Verb-Noun with dash = Get-Process [OK]
Hint: Cmdlets always use Verb-Noun with a dash [OK]
Common Mistakes:
  • Using camelCase or underscores
  • Reversing noun and verb order
  • Omitting the dash between verb and noun
3. What will be the output of this PowerShell command?
Get-Process | Where-Object { $_.CPU -gt 100 }
medium
A. Shows an error because CPU is not a valid property.
B. Lists all processes using less than 100 CPU seconds.
C. Lists all processes regardless of CPU usage.
D. Lists all processes using more than 100 CPU seconds.

Solution

  1. Step 1: Understand the pipeline

    Get-Process gets all processes; Where-Object filters them.
  2. Step 2: Analyze the filter condition

    It selects processes where CPU time is greater than 100 seconds.
  3. Final Answer:

    Lists all processes using more than 100 CPU seconds. -> Option D
  4. Quick Check:

    CPU > 100 filters processes correctly [OK]
Hint: Where-Object filters output by condition [OK]
Common Mistakes:
  • Confusing greater than with less than
  • Assuming CPU is invalid property
  • Ignoring the filter and expecting all processes
4. Identify the error in this PowerShell command:
Get-Process | Where-Object { $_.cpu -gt 100 }
medium
A. There is no error in the command.
B. The pipe symbol '|' is used incorrectly here.
C. Where-Object cannot filter numeric properties.
D. The property name 'cpu' is case-sensitive and should be 'CPU'.

Solution

  1. Step 1: Check property names in PowerShell

    Property names are case-insensitive in PowerShell, so 'cpu' works.
  2. Step 2: Verify other parts

    Pipe usage and braces are correct; Where-Object filters numeric properties fine.
  3. Step 3: Reconsider case sensitivity

    Actually, property names are not case-sensitive, so no error here.
  4. Final Answer:

    There is no error in the command. -> Option A
  5. Quick Check:

    Property names are case-insensitive [OK]
Hint: PowerShell property names ignore case [OK]
Common Mistakes:
  • Thinking property names are case-sensitive
  • Misunderstanding pipe usage
  • Assuming missing braces
5. You want to automate a task that lists all services, filters only running ones, and sorts them by name. Which combination of cmdlets achieves this?
hard
A. Get-Service -Status Running | Sort-Object -Property Status
B. Get-Service | Where-Object { $_.Status -eq 'Running' } | Sort-Object Name
C. Get-Process | Where-Object { $_.Status -eq 'Running' } | Sort-Object Name
D. Get-Service | Sort-Object Status | Where-Object { $_.Status -eq 'Running' }

Solution

  1. Step 1: Identify cmdlet to get services

    Get-Service retrieves all services.
  2. Step 2: Filter running services correctly

    Where-Object filters services where Status equals 'Running'.
  3. Step 3: Sort filtered services by name

    Sort-Object sorts the filtered list by the Name property.
  4. Final Answer:

    Get-Service | Where-Object { $_.Status -eq 'Running' } | Sort-Object Name -> Option B
  5. Quick Check:

    Filter then sort = Get-Service | Where-Object { $_.Status -eq 'Running' } | Sort-Object Name [OK]
Hint: Filter first, then sort for correct results [OK]
Common Mistakes:
  • Filtering after sorting loses efficiency
  • Using Get-Process instead of Get-Service
  • Sorting by wrong property
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