Bird
0
0

What will be the output of this PowerShell code?

medium📝 Command Output Q13 of 15
PowerShell - Remote Management
What will be the output of this PowerShell code?
 $session = New-PSSession -ComputerName localhost
Invoke-Command -Session $session -ScriptBlock { Get-Process | Select-Object -First 1 }
Remove-PSSession -Session $session 
ADisplays the first process running on the local computer
BCreates a session but does not display any output
CThrows an error because Remove-PSSession is called too early
DDisplays all processes running on the local computer
Step-by-Step Solution
Solution:
  1. Step 1: Understand the commands

    The code creates a session to localhost, runs a command to get the first process, then removes the session.
  2. Step 2: Analyze the Invoke-Command output

    The Invoke-Command runs Get-Process | Select-Object -First 1 remotely, so it outputs the first process object.
  3. Final Answer:

    Displays the first process running on the local computer -> Option A
  4. Quick Check:

    Invoke-Command outputs first process [OK]
Quick Trick: Invoke-Command outputs scriptblock result before Remove-PSSession [OK]
Common Mistakes:
  • Thinking Remove-PSSession stops output
  • Assuming no output from Invoke-Command
  • Confusing output with all processes

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes