Forum Discussion
Cannot dot-source this command because it was defined in a different language mode.
Microsoft.PowerShell_profile.ps1: Cannot dot-source this command because it was defined in a different language mode. To invoke this command without importing its contents, omit the '.' operator.
I am getting this error when I open my PowerShell anywhere... I have few scripts present in my PS Profile, but this is failing with error, and I can't import, its blocking me to even set a property.
$Host.Name = 'Test'
InvalidOperation: Cannot set property. Property setting is supported only on core types in this language mode.
Can someone please help me to get rid of this issue. Thanks!
12 Replies
- LainRobertsonSilver Contributor
Hi, Ravi.
If you run the following command, does it show as FullLanguage or another value? (I'm guessing it may be ConstrainedLanguage.)
$ExecutionContext.SessionState.LanguageMode
Incidentally, Name is a read-only attribute on $Host, meaning that won't work anyway.
If you were looking to change the windows title, you need to change $Host.UI.RawUI.WindowTitle:
$Host.UI.RawUI.WindowTitle = "Foo";
Cheers,
Lain
- RaviKiranSFormer Employee
LainRobertson - Yes, after some research, I also found that. It's in ConstrainedLanguage mode and not in FullLanguage. I am unable to change it to FullLanguage mode. Based on online articles, this will be temporary for the current session but for me it's everywhere and I am unable to change it.
Can you please help me to change it. Thanks!
- raindropsdevIron ContributorHere it says that it's activated automatically when Device Guard is enabled: https://devblogs.microsoft.com/powershell/powershell-constrained-language-mode/
Can you try disabling Device Guard and/or Applocker?