受限语言模式是否默认启用?

受限语言模式是否默认启用?

Powershell 中默认启用了受限语言模式吗?在最新的 Windows 10 FCU 版本中,最新

答案1

您还可以通过 __PSLockdownPolicy 环境变量来控制这一点。值为 0 将导致 FullLanguage,值为 4 将使其转变为 ConstrainedLanguage。

答案2

不,您只需设置一个属性即可将 PowerShell 会话置于受限语言模式:

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

更多详细信息,请阅读官方文档:什么是 PowerShell 约束语言? https://blogs.msdn.microsoft.com/powershell/2017/11/02/powershell-constrained-language-mode/

相关内容