Forum Discussion

RaviKiranS's avatar
RaviKiranS
Former Employee
Oct 02, 2022

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

  • LainRobertson's avatar
    LainRobertson
    Silver Contributor

    RaviKiranS 

     

    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

    • RaviKiranS's avatar
      RaviKiranS
      Former 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!

Resources