Bird
Raised Fist0
PowerShellscripting~10 mins

Select-Object for properties in PowerShell - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to select only the 'Name' property from the process list.

PowerShell
Get-Process | Select-Object [1]
Drag options to blanks, or click blank then click option'
A-ExpandProperty Name
B-InputObject Name
C-Property Name
D-Filter Name
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-ExpandProperty' instead of '-Property' when you want to keep the property as an object.
Using '-InputObject' which is not valid here.
Using '-Filter' which is not a parameter for Select-Object.
2fill in blank
medium

Complete the code to select the 'Id' property from the process list.

PowerShell
Get-Process | Select-Object [1]
Drag options to blanks, or click blank then click option'
A-Property Id
B-Filter Id
C-InputObject Id
D-ExpandProperty Id
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-ExpandProperty' which extracts the value instead of keeping it as a property.
Using '-InputObject' or '-Filter' which are not valid parameters here.
3fill in blank
hard

Fix the error in the code to select the 'CPU' property from the process list.

PowerShell
Get-Process | Select-Object [1]
Drag options to blanks, or click blank then click option'
A-Filter CPU
B-ExpandProperty CPU
C-InputObject CPU
D-Property CPU
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-ExpandProperty' which returns only the value, not an object with property.
Using '-InputObject' or '-Filter' which are invalid here.
4fill in blank
hard

Fill both blanks to select 'Name' and 'Id' properties from the process list.

PowerShell
Get-Process | Select-Object [1] [2]
Drag options to blanks, or click blank then click option'
A-Property Name
B-Property Id
C-ExpandProperty Name
D-ExpandProperty Id
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-ExpandProperty' which only works for one property at a time.
Mixing '-Property' and '-ExpandProperty' in the same command.
5fill in blank
hard

Fill all three blanks to select 'Name', 'Id', and 'CPU' properties from the process list.

PowerShell
Get-Process | Select-Object [1] [2] [3]
Drag options to blanks, or click blank then click option'
A-Property Name
B-Property Id
C-Property CPU
D-ExpandProperty CPU
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-ExpandProperty' which only works for one property and returns values, not objects.
Mixing '-Property' and '-ExpandProperty' in the same command.

Practice

(1/5)
1. What does the PowerShell cmdlet Select-Object do when used with property names?
easy
A. It shows only the specified properties from the objects passed to it.
B. It deletes the specified properties from the objects.
C. It renames the specified properties in the output.
D. It sorts the objects based on the specified properties.

Solution

  1. Step 1: Understand Select-Object purpose

    Select-Object is used to pick specific properties from objects, filtering out others.
  2. Step 2: Analyze the effect of specifying properties

    When you give property names, Select-Object returns only those properties in the output.
  3. Final Answer:

    It shows only the specified properties from the objects passed to it. -> Option A
  4. Quick Check:

    Select-Object with properties = show those properties [OK]
Hint: Select-Object picks only listed properties to simplify output [OK]
Common Mistakes:
  • Thinking Select-Object deletes properties permanently
  • Confusing Select-Object with Sort-Object
  • Assuming it renames properties automatically
2. Which of the following is the correct syntax to select only the 'Name' and 'Id' properties from a list of processes?
easy
A. Get-Process | Select-Object Name, Id
B. Get-Process | Select-Object -Select Name, Id
C. Get-Process | Select-Object -Properties Name Id
D. Get-Process | Select-Object -Property Name, Id

Solution

  1. Step 1: Recall Select-Object syntax

    The correct parameter to specify properties is '-Property' followed by a comma-separated list.
  2. Step 2: Check each option

    Get-Process | Select-Object -Property Name, Id uses '-Property Name, Id' which is correct syntax. Get-Process | Select-Object Name, Id misses the dash before Property. Get-Process | Select-Object -Properties Name Id misses commas and uses incorrect parameter '-Properties'. Get-Process | Select-Object -Select Name, Id uses invalid '-Select'.
  3. Final Answer:

    Get-Process | Select-Object -Property Name, Id -> Option D
  4. Quick Check:

    Correct parameter is -Property with commas [OK]
Hint: Use -Property with commas to list properties [OK]
Common Mistakes:
  • Omitting the dash before 'Property'
  • Using spaces instead of commas between properties
  • Using wrong parameter names like -Select or -Properties
3. What will be the output of this command?
Get-Process | Select-Object -Property Name, CPU | Select-Object -First 3
medium
A. The first 3 processes showing only their Name and CPU usage.
B. All processes showing Name and CPU usage.
C. An error because Select-Object cannot be chained.
D. The first 3 processes showing all properties.

Solution

  1. Step 1: Understand the first Select-Object

    The first Select-Object filters each process object to only include Name and CPU properties.
  2. Step 2: Understand the second Select-Object

    The second Select-Object with -First 3 takes only the first 3 objects from the filtered list.
  3. Final Answer:

    The first 3 processes showing only their Name and CPU usage. -> Option A
  4. Quick Check:

    Chaining Select-Object filters properties then limits output [OK]
Hint: Chain Select-Object to filter properties then limit output [OK]
Common Mistakes:
  • Thinking Select-Object cannot be chained
  • Expecting all properties after filtering
  • Confusing -First with property selection
4. You run this command but get an error:
Get-Service | Select-Object Name Status, DisplayName

What is the problem?
medium
A. Get-Service does not output objects with these properties.
B. Missing commas between property names causes syntax error.
C. Select-Object cannot be used with Get-Service.
D. The command is correct and should not error.

Solution

  1. Step 1: Check property list syntax

    Properties must be separated by commas. Here 'Name Status' lacks a comma.
  2. Step 2: Understand error cause

    Without commas, PowerShell treats 'Name Status' as one invalid property, causing an error.
  3. Final Answer:

    Missing commas between property names causes syntax error. -> Option B
  4. Quick Check:

    Always separate property names with commas [OK]
Hint: Separate property names with commas to avoid errors [OK]
Common Mistakes:
  • Forgetting commas between property names
  • Assuming spaces separate properties
  • Thinking Get-Service output is incompatible
5. You want to create a list of running processes showing only their 'Name' and 'Id', but also add a new property 'ShortName' that shows the first 3 letters of the process name. Which command achieves this?
hard
A. Get-Process | Select-Object -Property Name, Id, ShortName
B. Get-Process | Select-Object Name, Id, ShortName = $_.Name.Substring(0,3)
C. Get-Process | Select-Object Name, Id, @{Name='ShortName';Expression={$_.Name.Substring(0,3)}}
D. Get-Process | Select-Object Name, Id | Add-Member -Name ShortName -Value {$_.Name.Substring(0,3)}

Solution

  1. Step 1: Understand how to add calculated properties

    Use a hashtable with Name and Expression keys inside Select-Object to add new properties.
  2. Step 2: Check each option

    Get-Process | Select-Object Name, Id, @{Name='ShortName';Expression={$_.Name.Substring(0,3)}} correctly uses @{Name='ShortName';Expression={$_.Name.Substring(0,3)}} to add the new property. Get-Process | Select-Object Name, Id, ShortName = $_.Name.Substring(0,3) has wrong syntax. Get-Process | Select-Object -Property Name, Id, ShortName tries to select a non-existent property. Get-Process | Select-Object Name, Id | Add-Member -Name ShortName -Value {$_.Name.Substring(0,3)} uses Add-Member incorrectly for pipeline objects.
  3. Final Answer:

    Get-Process | Select-Object Name, Id, @{Name='ShortName';Expression={$_.Name.Substring(0,3)}} -> Option C
  4. Quick Check:

    Use hashtable with Expression to add calculated property [OK]
Hint: Add calculated properties with @{Name='';Expression={}} in Select-Object [OK]
Common Mistakes:
  • Trying to assign calculated properties directly without hashtable
  • Selecting non-existent properties without calculation
  • Using Add-Member incorrectly in pipeline
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