2

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]

3 Answers 3

0

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.

Sign up to request clarification or add additional context in comments.

5 Comments

I apologize for my misunderstanding, but I really don't know what audit mode is, and all of this is new to me. I know that the command does not succeed, and all FullLanguage commands also do not succeed, so I don't think I am in audit mode. Sorry for the late response, I have a lot of homework, and thanks for responding at all.
@NathanKalusa, the audit-mode remark was just an aside, and doesn't apply to your case. The bottom line is that if one of the two policies mentioned in the answer are in place, you'll need to ask whoever has the power to change them so as to allow you to use FullLanguage mode - assuming they're willing to do that.
If I have Administrator rights on my PC how can I then do it myself?
@OliverNilsen, I have no personal experience with WDAC or AppLocker, but perhaps the links in the answer help.
The condition Powershell uses for "Constrained Mode" with AppLocker is that it cannot run a script in it's temp directory. Change $env:TMP (and maybe $env:TEMP) to a script running location before starting the shell and you'll get Full mode in that case.
0

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)

1 Comment

This won't work if Constrained Language Mode is imposed by a WDAC or AppLocker policy.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.