Bird
0
0

What will be the output of this code?

medium📝 Command Output Q4 of 15
PowerShell - Remote Management
What will be the output of this code?
$session = New-PSSession -ComputerName Server01
Get-PSSession -Id $session.Id | Select-Object ComputerName
AAn error because Get-PSSession does not accept -Id
BId<br>--<br>1
CNo output because session is not connected
DComputerName<br>------------<br>Server01
Step-by-Step Solution
Solution:
  1. Step 1: Understand New-PSSession and Get-PSSession usage

    New-PSSession creates a session object with an Id and ComputerName. Get-PSSession can filter by -Id.
  2. Step 2: Analyze the output of Select-Object ComputerName

    It will display the ComputerName property of the session, which is Server01.
  3. Final Answer:

    ComputerName
    ------------
    Server01
    -> Option D
  4. Quick Check:

    Get-PSSession -Id returns session info including ComputerName [OK]
Quick Trick: Get-PSSession -Id returns session details including ComputerName [OK]
Common Mistakes:
  • Thinking Get-PSSession can't filter by -Id
  • Expecting Id property output instead of ComputerName
  • Assuming session is not connected and returns nothing

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes