I'm a coding collage major, and I am using my school's computer to make a cross-platform script for Linux and Windows. I need to run the script to test it, but PowerShell keeps responding with
Cannot create type. Only core types are supported in this language mode.
I cannot use admin, as this is not my computer. I really don't wanna restart on my home computer, and then I cannot work on it in class. Can anyone help?
I tried inputting $ExecutionContext.SessionState.LanguageMode = 'fulllanguage'
but it still did not work. PowerShell responded with
InvalidOperation: Cannot set property. Property setting is supported only on core types in this language mode.
When I boot up PowerShell, the starting text is
PowerShell 7.4.1
[Constrained Language Mode]
By security-minded design, you cannot switch from a more restrictive PowerShell language mode to a more permissive one in-session.
Therefore, executing $ExecutionContext.SessionState.LanguageMode = 'FullLanguage'
, i.e. switching to unrestricted use of all language features is pointless, because the command will only succeed if you're already in that language mode.[1]
If your PowerShell sessions are forced into ConstrainedLanguage
mode by a WDAC or AppLocker policy, the only way to put them into FullLanguage
mode is by changing the policy - which requires elevation (running with administrative privileges), so you may have to ask your IT department for assistance - assuming they're willing to allow you access to FullLanguageMode
.
[1] There appears to be a limited exception, but I'm unclear on whether the behavior is intentional or not. PowerShell 7.4 introduced an audit-only ConstrainedLanguage
mode that in effect behaves like FullLanguage
, but logs as if ConstrainedLanguage
mode were in effect. In this audit-only mode, $ExecutionContext.SessionState.LanguageMode = 'FullLanguage'
apparently succeeds (which would disable the logging part) - see GitHub issue #20768.