Is something wrong with my $PROFILE environment variable?
Asked Answered
F

2

5

If I execute

& $PROFILE

I get this error

& : The term 'C:\Users\stib\Documents\WindowsPowerShell\
Microsoft.PowerShell_profile.ps1' is not recognized as the name of a cmdlet,
function, script file, or operable program. Check the spelling of the name,
or if a path was included, verify that the path is correct and try again.
At line:1 char:3
+ & $PROFILE
+   ~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\stib...ell_profile.ps1:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

The correct profile is found at $PROFILE.CurrentUserAllHosts. Is there something wrong with my setup?

Frumpish answered 28/2, 2019 at 23:16 Comment(4)
Go to C:\Users\stib\Documents\WindowsPowerShell I am sure you will find that you don't have a Microsoft.PowerShell_profile.ps1Highchair
What Drew said. Run & $PROFILE.CurrentUserAllHosts if that's what you actually want executed. That shouldn't be necessary, though, b/c PowerShell should automatically load the relevant profiles upon launch.Inconsequent
Yep, when I start a PS Session my profile is loaded correctly, I was just wondering if I'd misconfigured something (as I am wont to do).Frumpish
related: https://mcmap.net/q/282523/-windows-powershell-profile-does-not-show-a-real-pathShellfish
M
5

The reason for this behavior is the default selection for $Profile.ToString() that gets called when you invoke it using the & operator (which is $Profile.CurrentUserCurrentHost).

Selectively execute your profiles instead of relying on defaults:

& $Profile.CurrentUserAllHosts

As a footnote, $Profile is just an extended System.String with added properties and a modified ToString method. See:

$Profile | Get-Member -MemberType NoteProperty

Additionally, the profiles that apply to your current shell are automatically executed when you launch that shell unless -NoProfile is passed to the executable.

Molloy answered 28/2, 2019 at 23:26 Comment(0)
I
1

I ran into this issue when setting oh-my-posh up because of the way my work computers are configured.

I just created the file that was missing and then everything worked OK.

Intertwine answered 1/6, 2022 at 10:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.