Skip to content

Scopes vs Session States (+ runspaces) #10797

@ohads-MSFT

Description

@ohads-MSFT

Type of issue

Missing information

Feedback

The scope docs mention session state but don't explain what it is (or even reference docs to that effect):
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_scopes?view=powershell-7.4

A quick search turned up the following docs (which are titled as to be specific for Windows PowerShell):
https://learn.microsoft.com/en-us/powershell/scripting/developer/cmdlet/windows-powershell-session-state?view=powershell-7.4
However, they refer to the session state as a configuration/data/information holder, which doesn't explain how session state can be "linked" to the global scope (to use the language of the above scope docs). Also, they refer to PowerShell runspaces which aren't documented at all as far as I can tell (I could only find this archived blog post: https://devblogs.microsoft.com/scripting/beginning-use-of-powershell-runspaces-part-1/).

Finally, the Import-Module docs (specifically for the Scope parameter) are possibly the most confusing of all:
https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/import-module?view=powershell-7.4
These docs repeatedly mix scopes and session states as if they were interchangeable (which would contradict the other docs). For example:

By default, when Import-Module cmdlet is called from the command prompt, script file, or scriptblock, all the commands are imported into the global session state. You can use the -Scope Local parameter to import module content into the script or scriptblock scope.

Page URL

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_scopes?view=powershell-7.4

Content source URL

https://github.com/MicrosoftDocs/PowerShell-Docs/blob/main/reference/7.4/Microsoft.PowerShell.Core/About/about_Scopes.md

Author

@sdwheeler

Document Id

42772fd1-35e3-2672-05b1-3e5cd9c31ecf

Metadata

Metadata

Assignees

Labels

area-aboutArea - About_ topics

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions