0
0
PowerShellscripting~20 mins

PSSession management in PowerShell - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
PSSession Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
What is the output of this PowerShell command?
You create a new PSSession to a remote computer and then list all active sessions. What will this command output?
PowerShell
New-PSSession -ComputerName Server01
Get-PSSession | Select-Object -Property ComputerName, State
A@{ComputerName=Server01; State=Opened}
B@{ComputerName=Server01; State=Disconnected}
CNo output, because Get-PSSession requires a session ID
DError: New-PSSession requires credentials
Attempts:
2 left
💡 Hint
Think about what state a newly created PSSession has before you disconnect it.
📝 Syntax
intermediate
2:00remaining
Which command correctly closes and removes all PSSessions?
You want to close all active PSSessions and remove them from your session list. Which command does this correctly?
AGet-PSSession | Close-PSSession
BGet-PSSession | Remove-PSSession
CClose-PSSession -All
DRemove-PSSession -All
Attempts:
2 left
💡 Hint
Remember the cmdlet used to remove sessions is Remove-PSSession.
🔧 Debug
advanced
2:00remaining
Why does this script fail to reconnect to a disconnected PSSession?
You run this script but get an error when trying to reconnect: $session = New-PSSession -ComputerName Server01 Disconnect-PSSession -Session $session Connect-PSSession -Session $session
PowerShell
$session = New-PSSession -ComputerName Server01
Disconnect-PSSession -Session $session
Connect-PSSession -Session $session
AConnect-PSSession cmdlet does not exist; use Connect-PSSession only in PowerShell 7+
BConnect-PSSession requires the session to be in Disconnected state, but the session was never disconnected properly
CConnect-PSSession is not a valid cmdlet; use Connect-PSSession only with disconnected sessions
DThe cmdlet name is incorrect; it should be 'Connect-PSSession' replaced with 'Connect-PSSession -Id <id>'
Attempts:
2 left
💡 Hint
Check if Connect-PSSession is a valid cmdlet in PowerShell.
🚀 Application
advanced
2:00remaining
How many PSSessions remain after running this script?
You run this script: $s1 = New-PSSession -ComputerName Server01 $s2 = New-PSSession -ComputerName Server02 Remove-PSSession -Session $s1 Get-PSSession | Measure-Object | Select-Object -ExpandProperty Count What is the output number?
PowerShell
$s1 = New-PSSession -ComputerName Server01
$s2 = New-PSSession -ComputerName Server02
Remove-PSSession -Session $s1
Get-PSSession | Measure-Object | Select-Object -ExpandProperty Count
AError: Remove-PSSession requires session ID
B2
C0
D1
Attempts:
2 left
💡 Hint
Think about how many sessions you created and how many you removed.
🧠 Conceptual
expert
2:00remaining
What is the main benefit of using PSSession over Invoke-Command for multiple commands?
You want to run several commands on a remote computer efficiently. Why choose PSSession instead of multiple Invoke-Command calls?
APSSession automatically retries commands on failure, Invoke-Command does not
BInvoke-Command cannot run multiple commands on the same remote computer
CPSSession keeps a persistent connection, reducing overhead for multiple commands
DInvoke-Command requires credentials every time, PSSession does not
Attempts:
2 left
💡 Hint
Think about connection setup and reuse.