1
votes

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?

1
Go to C:\Users\stib\Documents\WindowsPowerShell I am sure you will find that you don't have a Microsoft.PowerShell_profile.ps1Drew
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.Ansgar Wiechers
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).stib

1 Answers

4
votes

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.