2

I have a problem where PowerShell will no longer run my Microsoft.Powershell_profile.ps1/Profile.ps1 script stating it can't "dot source" the file. This started after I ran a registry cleaner and system optimizer on my machine. Now, I can't figure out what setting has changed, been added, or revoked.

Things to note:

  • The console always defaults to 'ConstrainedLanguage' because of the attempt to "dot source"
  • I have tried setting the -ExecutionPolicy to both "Unrestricted" and "RemoteSigned" to no effect
  • Issue exists in both version 5 & 6
  • If I run the "PowerShell Integrated Console" in VS Code, as opposed to in the terminal window, it runs fine showing "FullLanguage"
  • The contents of the profile file do not matter - if I use an empty file, it still won't run.
  • Placing "Microsoft.Powershell_profile.ps1" in the "\documents" folder does NOT produce a "dot source" error, however it also doesn't recognize any commands from within the profile script.

Things I have tried:

  • Setting to "FullLanguage" via $ExecutionContext.SessionState.LanguageMode = 0 results in "Cannot set property. Property setting is supported only on core types in this language mode."
  • Setting the "__PSLockdownPolicy" property to 0 in the registry at "HKLM:\SYSTEM\CurrentControlSet\Control\Session Manager\Environment\" does nothing for v5 and crashes v6
  • Moving the profile file between $home, "\documents", and $pshome (location dependent on version) to no effect (with the above exception)
  • Adjusting name between "Microsoft.Powershell_profile.ps1" and "Profile.ps1" (normally adjusted to match intended audience ("All Users", for example) but am trying variations in hopes of making work)
  • Uninstalling and re-installing different 5.x and 6.x versions to no effect
  • Running "Powershell -noprofile" doesn't load the profile, so no error but still runs in "ConstrainedLanguage"
  • Verified AppLocker is not running / has not rules in place
  • Verified Controlled Folder Access is off

Any help would be appreciated.

Steven Kanberg
  • 6,078
  • 2
  • 16
  • 35
  • If you're using Windows 10, you could try doing a PC Reset, though IIRC, that means you'll have to re-install all your apps. – zdan Jan 28 '19 at 21:45
  • If you have access to security logs on the machine, check them to see what keys got changed, might be a pain but you could undo changes one a time to isolate what broke – trebleCode Jan 29 '19 at 16:22
  • Did you manage to solve the problem? – alamoot Sep 15 '22 at 16:37
  • Ultimately, yes, but not via an expected method. I ended up needing to get a new laptop and the issue wasn't present on that one. I never figured out what caused it and why I couldn't change it. – Steven Kanberg Sep 16 '22 at 23:44

0 Answers0