What does the <code>Select-Object</code> cmdlet do in PowerShell?
It selects specific properties of an object or set of objects, allowing you to focus on only the data you need.
Click to reveal answer
beginner
How do you select only the Name and Length properties from a list of files using Select-Object?
Use Get-ChildItem | Select-Object Name, Length. This shows just the file names and their sizes.
Click to reveal answer
beginner
What happens if you use Select-Object without specifying any properties?
It returns the whole object with all its properties unchanged.
Click to reveal answer
intermediate
Can Select-Object create new calculated properties? How?
Yes. You can use a hashtable with Name and Expression keys to define a new property based on existing data.
Click to reveal answer
beginner
Why is Select-Object useful when working with large data sets?
It helps reduce clutter by showing only the important properties, making output easier to read and process.
Click to reveal answer
Which command selects only the ProcessName and Id properties from running processes?
AGet-Process | Select-Object ProcessName, Id
BGet-Process | Where-Object ProcessName, Id
CGet-Process | Sort-Object ProcessName, Id
DGet-Process | Format-Table ProcessName, Id
✗ Incorrect
Select-Object is used to pick specific properties. Where-Object filters objects, Sort-Object sorts, and Format-Table formats output but does not select properties.
What will Get-ChildItem | Select-Object -First 3 do?
ASelect the first 3 properties of each file
BSelect the first 3 files from the list
CSelect files with size less than 3 bytes
DSelect files with names starting with '3'
✗ Incorrect
The -First parameter selects the first 3 objects (files) from the list, not properties.
How do you add a new property called SizeKB that shows file size in kilobytes using Select-Object?
Using a hashtable with Name and Expression keys creates a calculated property. 1KB is a PowerShell constant for 1024.
If you want to see all properties of an object, what should you do?
AUse <code>Get-Member</code>
BUse <code>Select-Object</code> with no arguments
CUse <code>Format-List *</code>
DUse <code>Select-Object *</code>
✗ Incorrect
Select-Object * selects all properties explicitly. Format-List * formats all properties for display, and Get-Member lists properties but does not show values.
What is the main benefit of using Select-Object in scripts?
ATo filter objects by property values
BTo sort objects alphabetically
CTo reduce output to only needed properties
DTo delete unwanted files
✗ Incorrect
Select-Object helps focus output on specific properties, making data easier to read and use.
Explain how to use Select-Object to show only certain properties from a list of files.
Think about how you pick only the details you want from a big list.
You got /4 concepts.
Describe how to create a new calculated property using Select-Object and why it might be useful.
Imagine adding a new column based on existing data.
You got /4 concepts.
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
Step 1: Understand Select-Object purpose
Select-Object is used to pick specific properties from objects, filtering out others.
Step 2: Analyze the effect of specifying properties
When you give property names, Select-Object returns only those properties in the output.
Final Answer:
It shows only the specified properties from the objects passed to it. -> Option A
Quick Check:
Select-Object with properties = show those properties [OK]
Hint: Select-Object picks only listed properties to simplify output [OK]
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
Step 1: Recall Select-Object syntax
The correct parameter to specify properties is '-Property' followed by a comma-separated list.
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'.
Final Answer:
Get-Process | Select-Object -Property Name, Id -> Option D
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
Step 1: Understand the first Select-Object
The first Select-Object filters each process object to only include Name and CPU properties.
Step 2: Understand the second Select-Object
The second Select-Object with -First 3 takes only the first 3 objects from the filtered list.
Final Answer:
The first 3 processes showing only their Name and CPU usage. -> Option A
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
Step 1: Check property list syntax
Properties must be separated by commas. Here 'Name Status' lacks a comma.
Step 2: Understand error cause
Without commas, PowerShell treats 'Name Status' as one invalid property, causing an error.
Final Answer:
Missing commas between property names causes syntax error. -> Option B
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
Step 1: Understand how to add calculated properties
Use a hashtable with Name and Expression keys inside Select-Object to add new properties.
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.
Final Answer:
Get-Process | Select-Object Name, Id, @{Name='ShortName';Expression={$_.Name.Substring(0,3)}} -> Option C
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 unknownstrongwhile earning +1 Grip toward your certificate.