concept PowerShell session in category powershell

appears as: PowerShell session, PowerShell sessions
Windows PowerShell in Action, Third Edition

This is an excerpt from Manning's book Windows PowerShell in Action, Third Edition.

But what happens when you want to cause a script to exit from within a function defined in that script? PowerShell has the exit statement to do exactly this. So far, you’ve been using this statement to exit a PowerShell session. But when exit is used inside a script, it exits that script. This is true even when called from a function in that script. Here’s what that looks like:

The ID number will change every time you access the sessions on the remote machine created by a PowerShell session other than your own. It’s worth giving your session distinctive names so that you can easily distinguish between sessions.

On the client end, if you don’t explicitly remove the sessions or set timeouts, local sessions will remain open until you end your PowerShell session. But what happens if the client fails for some reason without closing its sessions? If the PowerShell session is closed or the local machine crashes, the remote session will be terminated. If network connectivity is lost or the session times out (the default is two hours), the session may be put into a disconnected state. You can also put a session into a disconnected state manually.

Listing 12.5. Using variables in workflows
workflow demo-scope { # This is a workflow top-level variable $a = 22 "Initial value of A is: $a" # Access $a from Inlinescript (bringing a workflow #variable to the PowerShell session) using $using inlinescript {"PowerShell variable A is: $a"} inlinescript {"Workflow variable A is: $using:a"} ## changing a variable value $a = InlineScript {$b = $Using:a+5; $b} "Workflow variable A after InlineScript change is: $a" parallel { sequence { # Reading a top-level variable "Value of A inside parallel is: $a" # Updating a top-level variable with # $workflow:<variable name> $workflow:a = 3 } } "Updated value of A is: $a" } demo-scope