Bird
0
0

You want to list all running processes and display their names and memory usage using PowerShell objects. Which script correctly uses object properties to do this?

hard📝 Application Q15 of 15
PowerShell - Working with Objects
You want to list all running processes and display their names and memory usage using PowerShell objects. Which script correctly uses object properties to do this?
AGet-Process | ForEach-Object { '$_.Name uses $_.WorkingSet64 bytes' }
BGet-Process | ForEach-Object { "$_.Name uses $_.WorkingSet64() bytes" }
CGet-Process | ForEach-Object { $_.Name + ' uses ' + $_.WorkingSet64 + ' bytes' }
DGet-Process | ForEach-Object { $_->Name + ' uses ' + $_->WorkingSet64 + ' bytes' }
Step-by-Step Solution
Solution:
  1. Step 1: Understand property access and string concatenation

    Properties are accessed with dot notation without parentheses. Concatenate strings with + in PowerShell.
  2. Step 2: Analyze each option

    A uses quotes with variables inside strings incorrectly (no expansion). B uses () on property causing error. C uses invalid arrow notation. D correctly concatenates properties and strings.
  3. Final Answer:

    Get-Process | ForEach-Object { $_.Name + ' uses ' + $_.WorkingSet64 + ' bytes' } -> Option C
  4. Quick Check:

    Use dot notation and + for string concat [OK]
Quick Trick: Use dot notation and + for strings, no () or arrows [OK]
Common Mistakes:
  • Using () after properties
  • Using arrow notation -> which is invalid
  • Expecting variables to expand inside single quotes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes