2

I created the file C:\Users\<myname>\Documents\WindowsPowerShell\profile.ps1; however, PowerShell does not load it on launch. I have tested both the default PowerShell as well as VS Code's integrated PowerShell. I also tried renaming the profile.ps1 file to Microsoft.PowerShell_profile.ps1, but this changed nothing. I relaunched the applications in question after each change.

Running Test-Path $profile.CurrentUserAllHosts returns True.

The profile currently only contains one line (Set-PSReadlineKeyHandler -Key Tab -Function Complete). After launching PowerShell or VS Code's integrated shell, running Get-PSReadlineKeyHandler | findstr -i Tab reveals that it has not been set. Copying and pasting the line from the profile, running it, then running the Get-... command again reveals that it is properly set, and the change does what it's supposed to. Relaunching the shell reverts back to the default.

Is there some other step I need to do to get PowerShell to execute the profile? (I come from a Linux/UNIX background and I assume PowerShell works similarly, but of course PowerShell is designed completely differently). If there is no extra step, why does PowerShell not load the profile in this case?

Additional Info:

> $profile | Format-List * -force
AllUsersAllHosts       : C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
AllUsersCurrentHost    : C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
CurrentUserAllHosts    : C:\Users\<myname>\Documents\WindowsPowerShell\profile.ps1
CurrentUserCurrentHost : C:\Users\<myname>\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
Length                 : 76
  • Are you asking how to modify the default PowerShell profile? – Ramhound Nov 15 '17 at 20:52
  • Are you within a PowerShell console or PowerShell ISE. This makes a difference, and I am unable to submit my answer, until you provide that information. – Ramhound Nov 15 '17 at 20:55
  • I'm just using PowerShell.exe; $host.Name returns 'ConsoleHost' – Whimsical Seaplane Nov 15 '17 at 21:02
  • Update your question with the sanitized output of $PROFILE | Format-List * -Force – Ramhound Nov 15 '17 at 21:03
  • Have you tried modifying C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1? – Ramhound Nov 15 '17 at 21:14
2

Solution: change execution policy

  1. Launch PowerShell as administrator
  2. Set-ExecutionPolicy -ExecutionPolicy Unrestricted

The error message as shown:

. : File C:\Users\<myname>\Documents\WindowsPowerShell\profile.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at http://go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:3
+ . 'C:\Users\<myname>\Documents\WindowsPowerShell\profile.ps1'
+   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

The Lesson:

The odd thing is that I saw an error message (which was not important) every time I launched PS before so I just got used to ignoring it. Creating the profile.ps1 file caused the execution policy error to appear, but also caused the previous error to stop appearing, so I just skipped over it because, without reading the details, it just looked like the same block of red text. (The previous error now appears to be impossible to replicate, for some reason.)

In the end, the problem can be described as "User got used to ignoring trivial and unimportant error, so the important error went unnoticed."

  • This does not work for me. I even logged off and back on and then executed get-executionpolicy which returned Unrestricted. Yet still the shell is not running my profile.ps1 file. – Tevya Feb 28 at 18:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.