3

Is Constrained Language mode enabled in Powershell by default? in latest Windows 10 FCU build, up-to-date

Aoi. T_015
  • 209
  • 1
  • 3
  • 12

2 Answers2

5

No, you can place a PowerShell session into Constrained Language mode simply by setting a property:

PS C:\> $ExecutionContext.SessionState.LanguageMode
FullLanguage

PS C:\> $ExecutionContext.SessionState.LanguageMode = "ConstrainedLanguage"

PS C:\> $ExecutionContext.SessionState.LanguageMode
ConstrainedLanguage


PS C:\> [System.Console]::WriteLine("Hello")

Cannot invoke method. Method invocation is supported only on core types in this language mode.
At line:1 char:1
+ [System.Console]::WriteLine("Hello")
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : MethodInvocationNotSupportedInConstrainedLanguage

For more details, read this official document: What is PowerShell Constrained Language? https://blogs.msdn.microsoft.com/powershell/2017/11/02/powershell-constrained-language-mode/

Mokubai
  • 89,133
  • 25
  • 207
  • 233
Waka
  • 1,164
  • 6
  • 5
  • if it's already in ConstraingedLanguage mode, it can't be set to FullLanguage with this method – K.H. B Jun 19 '19 at 01:53
4

You can also control this via __PSLockdownPolicy env variable. A value of 0 will result in FullLanguage and value of 4 will shift it to ConstrainedLanguage.

user871300
  • 56
  • 1