Skip to content

Fixed powershell profile fix #542

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
FreshSoftware4 opened this issue Apr 15, 2025 · 3 comments
Closed

Fixed powershell profile fix #542

FreshSoftware4 opened this issue Apr 15, 2025 · 3 comments

Comments

@FreshSoftware4
Copy link

I kept getting this error message on powershell and was wondering what it could be from:

PowerShell 7.5.0
\System.Management.Automation.Internal.Host.InternalHost.UI.RawUI: C:\Users\Eino\Documents\PowerShell\Microsoft.PowerShell_profile.ps1:2
Line |
   2 |  if (\System.Management.Automation.Internal.Host.InternalHost.UI.RawUI …
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The term '\System.Management.Automation.Internal.Host.InternalHost.UI.RawUI' is not recognized as a name of a
     | cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was
     | included, verify that the path is correct and try again.
Loading personal and system profiles took 681ms.

So I went to my favorite brainless assistant (chatgpt) for answers, and the fix was to edit Microsoft.PowerShell_profile.ps1 from this:

# Begin XPipe Fix - ensure profile runs only in interactive sessions
if (\System.Management.Automation.Internal.Host.InternalHost.UI.RawUI -and \System.Management.Automation.Internal.Host.InternalHost.Name -eq "ConsoleHost") {

#f45873b3-b655-43a6-b217-97c00aa0db58 PowerToys CommandNotFound module

Import-Module -Name Microsoft.WinGet.CommandNotFound
#f45873b3-b655-43a6-b217-97c00aa0db58

}
# End XPipe Fix

to this:

# Begin XPipe Fix - ensure profile runs only in interactive sessions
if ($host.UI.RawUI -and $host.Name -eq "ConsoleHost") {

    # f45873b3-b655-43a6-b217-97c00aa0db58 PowerToys CommandNotFound module
    Import-Module -Name Microsoft.WinGet.CommandNotFound
    # f45873b3-b655-43a6-b217-97c00aa0db58

}
# End XPipe Fix

And viola - no more error message when powershell opens. I suggest this fix or something like it be applied to fix the error at the source.

@crschnick
Copy link
Member

Yeah, that is a bit unfortunate that some powershell modules don't perform this check by themselves. The only alternative would be to just not load any profile for non-interactive sessions, but that would also not be ideal

@crschnick
Copy link
Member

I tried to fix this in https://github.com/xpipe-io/xpipe-ptb by just not running the profile in non-interactive mode. You can try whether it works for you now even without the adjustment to the profile file

@crschnick
Copy link
Member

This is now fixed in 16.0 by not loading the profile in non-interactive mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants