D. Using parentheses after 'Length' property causes an error
Solution
Step 1: Check property access syntax
Properties like 'Length' are accessed without parentheses in PowerShell.
Step 2: Identify the error
$file.Length() tries to call 'Length' as a method, causing an error.
Final Answer:
Using parentheses after 'Length' property causes an error -> Option D
Quick Check:
Properties do not use () [OK]
Hint: Properties never have () after them [OK]
Common Mistakes:
Adding () to properties
Thinking Get-Item can't get file info
Believing Write-Output can't print variables
5. 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
A. Get-Process | ForEach-Object { '$_.Name uses $_.WorkingSet64 bytes' }
B. Get-Process | ForEach-Object { "$_.Name uses $_.WorkingSet64() bytes" }
Step 1: Understand property access and string concatenation
Properties are accessed with dot notation without parentheses. Concatenate strings with + in PowerShell.
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.