Skip to content

Commit 836bf1f

Browse files
Fix inaccuracies in about_Language_Modes and minor formatting changes (#11979)
* Remove invalid types from v5.1's core type list The types removed from the core types list (permitted in ConstrainedLanguage mode) are only applicable to PS v6+, so are removed from the Windows PowerShell v5.1 document. Unlike in later versions, [ordered] is not a type (accelerator) in v5.1. * Add [ref] special case for ConstrainedLanguage [ref] is found in CoreTypes and is therefore permitted in ConstrainedLanguage mode. However, casting is not permitted and results in a statement-terminating error. Other uses (new() instantiation, in parameter binding, etc) are permitted. * Minor formatting changes to about_Language_Modes * Add note on Windows-only CoreTypes * Add note on [ordered] caveats in v5.1 CL mode In v5.1, [ordered] is not a type, nor is OrderedDictionary included in CoreTypes. [ordered] @{} syntax is permitted in v5.1 ConstrainedLanguage mode, but use of the object is limited. * Remove invalid variable from v5.1's RL mode list
1 parent 04a42a9 commit 836bf1f

File tree

4 files changed

+115
-75
lines changed

4 files changed

+115
-75
lines changed

reference/5.1/Microsoft.PowerShell.Core/About/about_Language_Modes.md

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Explains language modes and their effect on PowerShell sessions.
33
Locale: en-US
4-
ms.date: 10/04/2023
4+
ms.date: 04/03/2025
55
no-loc: [FullLanguage, ConstrainedLanguage, RestrictedLanguage, NoLanguage]
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_language_modes?view=powershell-5.1&WT.mc_id=ps-gethelp
77
schema: 2.0.0
@@ -50,14 +50,17 @@ For example:
5050

5151
```powershell
5252
$ExecutionContext.SessionState.LanguageMode
53+
```
54+
55+
```Output
5356
ConstrainedLanguage
5457
```
5558

5659
However, in sessions with `RestrictedLanguage` and `NoLanguage` modes, you
5760
can't use the [member-access operator][02] (`.`) to get property values.
5861
Instead, 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
8592
FullLanguage
8693
```
8794

@@ -117,11 +124,10 @@ application control policy. For example, there are additional restrictions to
117124
dot-sourcing and module importing under a policy.
118125

119126
When 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

126132
Any 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

147153
This section describes the language modes in PowerShell sessions.
148154

149-
### FullLanguage mode
155+
### `FullLanguage` mode
150156

151157
The `FullLanguage` mode permits all language elements in the session.
152158
`FullLanguage` is the default language mode for default sessions on all
153159
versions of Windows.
154160

155-
### RestrictedLanguage mode
161+
### `RestrictedLanguage` mode
156162

157163
In `RestrictedLanguage` mode, users can run commands (cmdlets, functions, CIM
158164
commands, 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

181186
Only the following comparison operators are permitted:
182187

@@ -186,7 +191,7 @@ Only the following comparison operators are permitted:
186191

187192
Assignment 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
192197
loops, conditionals, string expansion, and access to object properties. The
@@ -221,7 +226,7 @@ The features of `ConstrainedLanguage` mode are as follows:
221226
The following .NET types are permitted in `ConstrainedLanguage` mode. Users can
222227
get 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

328332
PowerShell `NoLanguage` mode disables PowerShell scripting language completely.
329333
You can't run scripts or use variables. You can only run native commands and

reference/7.4/Microsoft.PowerShell.Core/About/about_Language_Modes.md

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
description: Explains language modes and their effect on PowerShell sessions.
33
Locale: en-US
4-
ms.date: 10/04/2023
4+
ms.date: 04/03/2025
55
no-loc: [FullLanguage, ConstrainedLanguage, RestrictedLanguage, NoLanguage]
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.core/about/about_language_modes?view=powershell-7.4&WT.mc_id=ps-gethelp
77
schema: 2.0.0
@@ -53,14 +53,17 @@ For example:
5353

5454
```powershell
5555
$ExecutionContext.SessionState.LanguageMode
56+
```
57+
58+
```Output
5659
ConstrainedLanguage
5760
```
5861

5962
However, in sessions with `RestrictedLanguage` and `NoLanguage` modes, you
6063
can't use the [member-access operator][02] (`.`) to get property values.
6164
Instead, the error message reveals the language mode.
6265

63-
When you run the `$ExecutionContext.SessionState.LanguageMode` command in a
66+
When you access `$ExecutionContext.SessionState.LanguageMode` in a
6467
`RestrictedLanguage` session, PowerShell returns the
6568
**PropertyReferenceNotSupportedInDataSection** and
6669
**VariableReferenceNotSupportedInDataSection** error messages.
@@ -71,8 +74,9 @@ When you run the `$ExecutionContext.SessionState.LanguageMode` command in a
7174
referenced in restricted language mode or a Data section is being
7275
referenced.
7376

74-
When you run the `$ExecutionContext.SessionState.LanguageMode` command in a
75-
NoLanguage session, PowerShell returns the **ScriptsNotAllowed** error message.
77+
When you access `$ExecutionContext.SessionState.LanguageMode` in a
78+
`NoLanguage` session, PowerShell returns the **ScriptsNotAllowed** error
79+
message.
7680

7781
- **ScriptsNotAllowed**: The syntax isn't supported by this runspace. This
7882
might be because it's in no-language mode.
@@ -85,6 +89,9 @@ language mode by getting the value of the **LanguageMode** property.
8589

8690
```powershell
8791
(Get-PSSessionConfiguration -Name Test).LanguageMode
92+
```
93+
94+
```Output
8895
FullLanguage
8996
```
9097

@@ -149,13 +156,13 @@ For more information, see [JEA Session configurations][01] and
149156

150157
This section describes the language modes in PowerShell sessions.
151158

152-
### FullLanguage mode
159+
### `FullLanguage` mode
153160

154161
The `FullLanguage` mode permits all language elements in the session.
155162
`FullLanguage` is the default language mode for default sessions on all
156163
versions of Windows.
157164

158-
### RestrictedLanguage mode
165+
### `RestrictedLanguage` mode
159166

160167
In `RestrictedLanguage` mode, users can run commands (cmdlets, functions, CIM
161168
commands, and workflows), but can't use script blocks. This mode is also used
@@ -179,7 +186,7 @@ additional variables:
179186
- `$PSScriptRoot`
180187
- `$PSEdition`
181188
- `$EnabledExperimentalFeatures`
182-
- Any environment variables, like `$Env:TEMP`
189+
- Any environment variable, like `$env:TEMP`
183190

184191
Only the following comparison operators are permitted:
185192

@@ -189,7 +196,7 @@ Only the following comparison operators are permitted:
189196

190197
Assignment statements, property references, and method calls aren't permitted.
191198

192-
### ConstrainedLanguage mode
199+
### `ConstrainedLanguage` mode
193200

194201
`ConstrainedLanguage` mode is designed to allow basic language elements such as
195202
loops, conditionals, string expansion, and access to object properties. The
@@ -219,10 +226,10 @@ The features of `ConstrainedLanguage` mode are as follows:
219226
The following .NET types are permitted in `ConstrainedLanguage` mode. Users can
220227
get properties, invoke methods, and convert objects to these types.
221228

222-
Allowed Types:
229+
Allowed types:
223230

224-
- `[adsi]`
225-
- `[adsisearcher]`
231+
- `[adsi]` (Windows-only)
232+
- `[adsisearcher]` (Windows-only)
226233
- `[Alias]`
227234
- `[AllowEmptyCollection]`
228235
- `[AllowEmptyString]`
@@ -277,7 +284,6 @@ Allowed Types:
277284
- `[psobject]`
278285
- `[psprimitivedictionary]`
279286
- `[PSTypeNameAttribute]`
280-
- `[ref]`
281287
- `[regex]`
282288
- `[sbyte]`
283289
- `[securestring]`
@@ -310,9 +316,9 @@ Allowed Types:
310316
- `[version]`
311317
- `[void]`
312318
- `[WildcardPattern]`
313-
- `[wmi]`
314-
- `[wmiclass]`
315-
- `[wmisearcher]`
319+
- `[wmi]` (Windows-only)
320+
- `[wmiclass]` (Windows-only)
321+
- `[wmisearcher]` (Windows-only)
316322
- `[X500DistinguishedName]`
317323
- `[X509Certificate]`
318324
- `[xml]`
@@ -323,7 +329,13 @@ Only the following COM object types are permitted:
323329
- `Scripting.FileSystemObject`
324330
- `VBScript.RegExp`
325331

326-
### NoLanguage mode
332+
Special cases:
333+
334+
- `[ref]` - Casting an object to type `[ref]` or
335+
`[Management.Automation.PSReference]` is not permitted. Other uses are
336+
permitted.
337+
338+
### `NoLanguage` mode
327339

328340
PowerShell `NoLanguage` mode disables PowerShell scripting language completely.
329341
You can't run scripts or use variables. You can only run native commands and

0 commit comments

Comments
 (0)