Nathan Kalusa
Nathan Kalusa

Reputation: 33

PowerShell stuck in Constrained Language Mode

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]

Upvotes: 2

Views: 9402

Answers (3)

cheezeWhizze
cheezeWhizze

Reputation: 1

This suddenly happened to my win 11 entra id hybrid machine in Feb 2025. I don't know why--I found no applocker, SRP or WDAC policies, though it was acting like one was applied--I also could not run batch files.

To fix, I had to create a default policy in Local Security Policy under Software Restriction Policies. I just left the Security Levels at the default "unrestricted" and this fixed things after a reboot.

Upvotes: 0

user25459082
user25459082

Reputation: 1

https://www.youtube.com/watch?v=zW69MisrsWk

go to the chapter titled Constrained Language Mode and Just Delete __PSLockDownPolicy

If it does not work then set its value to 1 (that meaning re-add __PSLockDownPolicy back to your computer and then set it to 1)

Upvotes: 0

mklement0
mklement0

Reputation: 439777

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.

Upvotes: 0

Related Questions