11---
22description : Explains language modes and their effect on PowerShell sessions.
33Locale : en-US
4- ms.date : 10/ 04/2023
4+ ms.date : 04/03/2025
55no-loc : [FullLanguage, ConstrainedLanguage, RestrictedLanguage, NoLanguage]
66online version : https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_language_modes?view=powershell-5.1&WT.mc_id=ps-gethelp
77schema : 2.0.0
@@ -50,14 +50,17 @@ For example:
5050
5151``` powershell
5252$ExecutionContext.SessionState.LanguageMode
53+ ```
54+
55+ ``` Output
5356ConstrainedLanguage
5457```
5558
5659However, in sessions with ` RestrictedLanguage ` and ` NoLanguage ` modes, you
5760can't use the [ member-access operator] [ 02 ] (` . ` ) to get property values.
5861Instead, the error message reveals the language mode.
5962
60- When you run the ` $ExecutionContext.SessionState.LanguageMode ` command in a
63+ When you access ` $ExecutionContext.SessionState.LanguageMode ` in a
6164` RestrictedLanguage ` session, PowerShell returns the
6265** PropertyReferenceNotSupportedInDataSection** and
6366** VariableReferenceNotSupportedInDataSection** error messages.
@@ -68,8 +71,9 @@ When you run the `$ExecutionContext.SessionState.LanguageMode` command in a
6871 referenced in restricted language mode or a Data section is being
6972 referenced.
7073
71- When you run the ` $ExecutionContext.SessionState.LanguageMode ` command in a
72- NoLanguage session, PowerShell returns the ** ScriptsNotAllowed** error message.
74+ When you access ` $ExecutionContext.SessionState.LanguageMode ` in a
75+ ` NoLanguage ` session, PowerShell returns the ** ScriptsNotAllowed** error
76+ message.
7377
7478- ** ScriptsNotAllowed** : The syntax isn't supported by this runspace. This
7579 might be because it's in no-language mode.
@@ -82,6 +86,9 @@ language mode by getting the value of the **LanguageMode** property.
8286
8387``` powershell
8488(Get-PSSessionConfiguration -Name Test).LanguageMode
89+ ```
90+
91+ ``` Output
8592FullLanguage
8693```
8794
@@ -117,11 +124,10 @@ application control policy. For example, there are additional restrictions to
117124dot-sourcing and module importing under a policy.
118125
119126When a PowerShell session is started under a policy, it runs in
120- ` ConstrainedLanguage ` mode. This mode allows for a usable interactive shell
121- experience while limiting access to features and APIs that could be abused by a
122- malicious actor. Users can run cmdlets and native commands and have access to
123- basic language elements. Access to PowerShell, .NET, and COM APIs is
124- restricted.
127+ ` ConstrainedLanguage ` mode. This mode allows users to have a usable interactive
128+ shell experience, running cmdlets and native commands, as well as access to
129+ basic language elements. But the user can't access PowerShell, .NET, or COM
130+ APIs that could be abused by a malicious actor.
125131
126132Any script or script-based module executed in this session runs in
127133` ConstrainedLanguage ` mode. However, any script or script-based module allowed
@@ -146,13 +152,13 @@ For more information, see [JEA Session configurations][01] and
146152
147153This section describes the language modes in PowerShell sessions.
148154
149- ### FullLanguage mode
155+ ### ` FullLanguage ` mode
150156
151157The ` FullLanguage ` mode permits all language elements in the session.
152158` FullLanguage ` is the default language mode for default sessions on all
153159versions of Windows.
154160
155- ### RestrictedLanguage mode
161+ ### ` RestrictedLanguage ` mode
156162
157163In ` RestrictedLanguage ` mode, users can run commands (cmdlets, functions, CIM
158164commands, and workflows), but can't use script blocks. This mode is also used
@@ -175,8 +181,7 @@ additional variables:
175181
176182- ` $PSScriptRoot `
177183- ` $PSEdition `
178- - ` $EnabledExperimentalFeatures `
179- - Any environment variables, like ` $Env:TEMP `
184+ - Any environment variable, like ` $env:TEMP `
180185
181186Only the following comparison operators are permitted:
182187
@@ -186,7 +191,7 @@ Only the following comparison operators are permitted:
186191
187192Assignment statements, property references, and method calls aren't permitted.
188193
189- ### ConstrainedLanguage mode
194+ ### ` ConstrainedLanguage ` mode
190195
191196` ConstrainedLanguage ` mode is designed to allow basic language elements such as
192197loops, conditionals, string expansion, and access to object properties. The
@@ -221,7 +226,7 @@ The features of `ConstrainedLanguage` mode are as follows:
221226The following .NET types are permitted in ` ConstrainedLanguage ` mode. Users can
222227get properties, invoke methods, and convert objects to these types.
223228
224- Allowed Types :
229+ Allowed types :
225230
226231- ` [adsi] `
227232- ` [adsisearcher] `
@@ -230,7 +235,6 @@ Allowed Types:
230235- ` [AllowEmptyString] `
231236- ` [AllowNull] `
232237- ` [ArgumentCompleter] `
233- - ` [ArgumentCompletions] `
234238- ` [array] `
235239- ` [bigint] `
236240- ` [bool] `
@@ -249,9 +253,6 @@ Allowed Types:
249253- ` [DscLocalConfigurationManager] `
250254- ` [DscProperty] `
251255- ` [DscResource] `
252- - ` [ExperimentAction] `
253- - ` [Experimental] `
254- - ` [ExperimentalFeature] `
255256- ` [float] `
256257- ` [guid] `
257258- ` [hashtable] `
@@ -267,7 +268,6 @@ Allowed Types:
267268- ` [NullString] `
268269- ` [Object[]] `
269270- ` [ObjectSecurity] `
270- - ` [ordered] `
271271- ` [OutputType] `
272272- ` [Parameter] `
273273- ` [PhysicalAddress] `
@@ -278,24 +278,18 @@ Allowed Types:
278278- ` [psobject] `
279279- ` [psprimitivedictionary] `
280280- ` [PSTypeNameAttribute] `
281- - ` [ref] `
282281- ` [regex] `
283282- ` [sbyte] `
284283- ` [securestring] `
285- - ` [semver] `
286- - ` [short] `
287284- ` [single] `
288285- ` [string] `
289286- ` [SupportsWildcards] `
290287- ` [switch] `
291288- ` [timespan] `
292- - ` [uint] `
293289- ` [uint16] `
294290- ` [uint32] `
295291- ` [uint64] `
296- - ` [ulong] `
297292- ` [uri] `
298- - ` [ushort] `
299293- ` [ValidateCount] `
300294- ` [ValidateDrive] `
301295- ` [ValidateLength] `
@@ -323,7 +317,17 @@ Only the following COM object types are permitted:
323317- ` Scripting.FileSystemObject `
324318- ` VBScript.RegExp `
325319
326- ### NoLanguage mode
320+ Special cases:
321+
322+ - ` [ref] ` - Casting an object to type ` [ref] ` or
323+ ` [Management.Automation.PSReference] ` is not permitted. Other uses are
324+ permitted.
325+ - ` [ordered] ` - The ` [ordered] @{} ` expression is permitted and creates an
326+ object of type ` [Collections.Specialized.OrderedDictionary] ` . However,
327+ accessing methods of the object or directly instantiating an
328+ ** OrderedDictionary** is not permitted.
329+
330+ ### ` NoLanguage ` mode
327331
328332PowerShell ` NoLanguage ` mode disables PowerShell scripting language completely.
329333You can't run scripts or use variables. You can only run native commands and
0 commit comments