Eugeny / tabby

A terminal for a more modern age
https://tabby.sh
MIT License
57.96k stars 3.34k forks source link

Installing Alpha 132 broke my PowerShell #3447

Open mondash opened 3 years ago

mondash commented 3 years ago

After launching and opening PowerShell in Terminus after installing, I'm greeted with this list or errors. I'm still getting these errors even after uninstalling and restarting. Very unhappy ☹️ And this looked like such a cool product...

New-Object : The 'New-Object' command was found in the module 'Microsoft.PowerShell.Utility', but the module could not
be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Utility'.
At C:\Program Files\WindowsPowerShell\Modules\posh-git\1.0.0\Utils.ps1:8 char:17
+ $invokeErrors = New-Object System.Collections.ArrayList 256
+                 ~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (New-Object:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

Set-Alias : The 'Set-Alias' command was found in the module 'Microsoft.PowerShell.Utility', but the module could not
be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Utility'.
At C:\Program Files\WindowsPowerShell\Modules\posh-git\1.0.0\Utils.ps1:26 char:1
+ Set-Alias ?? Invoke-NullCoalescing -Force
+ ~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Set-Alias:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

New-Object : The 'New-Object' command was found in the module 'Microsoft.PowerShell.Utility', but the module could not
be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Utility'.
At C:\Program Files\WindowsPowerShell\Modules\posh-git\1.0.0\GitTabExpansion.ps1:4 char:26
+ $Global:GitTabSettings = New-Object PSObject -Property @{
+                          ~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (New-Object:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

Write-Debug : The 'Write-Debug' command was found in the module 'Microsoft.PowerShell.Utility', but the module could
not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Utility'.
At C:\Program Files\WindowsPowerShell\Modules\posh-git\1.0.0\GitTabExpansion.ps1:78 char:5
+     Write-Debug "Search for 'flow' in 'git help' output failed with e ...
+     ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Write-Debug:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

new-object : The 'new-object' command was found in the module 'Microsoft.PowerShell.Utility', but the module could not
be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Utility'.
At C:\Program Files\WindowsPowerShell\Modules\posh-git\1.0.0\TortoiseGit.ps1:12 char:31
+ $Global:TortoiseGitSettings = new-object PSObject -Property @{
+                               ~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (new-object:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

New-Object : The 'New-Object' command was found in the module 'Microsoft.PowerShell.Utility', but the module could not
be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Utility'.
At C:\Program Files\WindowsPowerShell\Modules\oh-my-posh\2.0.412\defaults.ps1:10 char:25
+ $global:ThemeSettings = New-Object -TypeName PSObject -Property @{
+                         ~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (New-Object:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

The property 'ErrorCount' cannot be found on this object. Verify that the property exists and can be set.
At C:\Program Files\WindowsPowerShell\Modules\oh-my-posh\2.0.412\oh-my-posh.psm1:202 char:1
+ $sl.ErrorCount = $global:error.Count
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyNotFound

Add-Type : The 'Add-Type' command was found in the module 'Microsoft.PowerShell.Utility', but the module could not be
loaded. For more information, run 'Import-Module Microsoft.PowerShell.Utility'.
At C:\Program Files\WindowsPowerShell\Modules\Get-ChildItemColor\2.2.0\Get-ChildItemColor.psm1:135 char:1
+ Add-Type -assemblyname System.ServiceProcess
+ ~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Add-Type:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

Import-Module : Cannot bind argument to parameter 'Name' because it is null.
At C:\Program Files\WindowsPowerShell\Modules\oh-my-posh\2.0.412\oh-my-posh.psm1:12 char:19
+     Import-Module $sl.CurrentThemeLocation -Force
+                   ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Import-Module], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ImportModul
   eCommand

Write-Host : The 'Write-Host' command was found in the module 'Microsoft.PowerShell.Utility', but the module could not
be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Utility'.
At C:\Program Files\WindowsPowerShell\Modules\oh-my-posh\2.0.412\oh-my-posh.psm1:129 char:9
+         Write-Host ''
+         ~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Write-Host:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

Write-Warning : The 'Write-Warning' command was found in the module 'Microsoft.PowerShell.Utility', but the module
could not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Utility'.
At C:\Program Files\WindowsPowerShell\Modules\oh-my-posh\2.0.412\oh-my-posh.psm1:130 char:9
+         Write-Warning "Theme $name not found. Available themes are:"
+         ~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Write-Warning:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

Sort-Object : The 'Sort-Object' command was found in the module 'Microsoft.PowerShell.Utility', but the module could
not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Utility'.
At C:\Program Files\WindowsPowerShell\Modules\oh-my-posh\2.0.412\oh-my-posh.psm1:171 char:89
+ ... \Themes\*" -Include '*.psm1' -Exclude Tools.ps1 | Sort-Object Name |  ...
+                                                       ~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Sort-Object:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

Import-Module : Cannot bind argument to parameter 'Name' because it is null.
At C:\Program Files\WindowsPowerShell\Modules\oh-my-posh\2.0.412\oh-my-posh.psm1:12 char:19
+     Import-Module $sl.CurrentThemeLocation -Force
+                   ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Import-Module], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ImportModul
   eCommand

Set-Alias : The 'Set-Alias' command was found in the module 'Microsoft.PowerShell.Utility', but the module could not
be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Utility'.
At C:\Users\*****\OneDrive\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:19 char:1
+ Set-Alias ls Get-ChildItemColor -option AllScope -Force
    + CategoryInfo          : ObjectNotFound: (Set-Alias:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

Set-Alias : The 'Set-Alias' command was found in the module 'Microsoft.PowerShell.Utility', but the module could not
At C:\Users\*****\OneDrive\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1:21 char:1
+ Set-Alias -Name dc -Value docker-compose
+ ~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Set-Alias:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

Set-Alias : The 'Set-Alias' command was found in the module 'Microsoft.PowerShell.Utility', but the module could not
be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Utility'.
At C:\ProgramData\chocolatey\helpers\functions\Update-SessionEnvironment.ps1:98 char:1
+ Set-Alias refreshenv Update-SessionEnvironment
+ ~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Set-Alias:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

New-Object : The 'New-Object' command was found in the module 'Microsoft.PowerShell.Utility', but the module could not
be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Utility'.
At C:\ProgramData\chocolatey\helpers\ChocolateyTabExpansion.ps1:21 char:33
+ $Global:ChocolateyTabSettings = New-Object PSObject -Property @{
+                                 ~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (New-Object:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

Even trying to run "clear" gives me the following error:

The 'Write-Host' command was found in the module 'Microsoft.PowerShell.Utility', but the module could not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Utility'.
At C:\Program Files\WindowsPowerShell\Modules\Get-ChildItemColor\2.2.0\Get-ChildItemColor.psm1:209 char:17
+                 Write-Host ""
+                 ~~~~~~~~~~

And running "ls" gives me this error:

Unable to find type [System.ServiceProcess.ServiceController].
At C:\Program Files\WindowsPowerShell\Modules\Get-ChildItemColor\2.2.0\Get-ChildItemColor.psm1:186 char:27
+             elseif($_ -is [System.ServiceProcess.ServiceController])
+                           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

I also just found out that this has left me with a dirty registry. I still have the "paste path into terminus" entry in the right click menu of my file explorer. I'm very unhappy that I tried this out at all and I could really use some help with fixing my PowerShell so I don't need to completely reinstall Windows 10.

I've tried SFC and DISM, both of which indicated that there were problems that they could not resolve.

Here's some more debug info I've aquired:

PS C:\Users\*****> Import-Module Microsoft.PowerShell.Utility
Import-Module : Could not load file or assembly 'Microsoft.PowerShell.Commands.Utility, Version=3.0.0.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The module was expected to contain an
assembly manifest.
At line:1 char:1
+ Import-Module Microsoft.PowerShell.Utility
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Import-Module], BadImageFormatException
    + FullyQualifiedErrorId : System.BadImageFormatException,Microsoft.PowerShell.Commands.ImportModuleCommand
Eugeny commented 3 years ago

Although Terminus doesn't affect the Powershell installation in any way except running powershell.exe, some people point out that the error above means problems with PSModulePath:

Measure-Object not found error with Enter-PSSession cmdlet - Windows Server
Enter-PSSession unexpectedly terminates when a network path is specified in PSModulePath.
mondash commented 3 years ago

Unfortunately, none of the fixes you mentioned above helped me. While the original error in those examples looks similar to mine, I don't think mine is the same. As shown in the description above, when I tried to directly run Import-Module Microsoft.PowerShell.Utility I got System.BadImageFormatException "The module was expected to contain an assembly manifest" and not "Failed to generate proxies for remote module 'Microsoft.PowerShell.Utility'". I'll provide my PSModulePath which confirms that I'm not using any network paths.

PS C:\Users\*****> $env:PSModulePath.split(';')
C:\Users\*****\OneDrive\Documents\WindowsPowerShell\Modules
C:\Program Files\WindowsPowerShell\Modules
C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
Eugeny commented 3 years ago

Sounds like the module DLLs are damaged, or were added in one of the earlier paths (C:\Users\*****\OneDrive\Documents\WindowsPowerShell\Modules), overriding the stock ones.

mondash commented 3 years ago

I think it is a bad DLL, specifically Microsoft.PowerShell.Commands.Utility. I see several mentions of it in my CBS.log (from running sfc) referencing mismatched hashes and corrupted payloads.

I don't have any modules in C:\Users\*****\OneDrive\Documents\WindowsPowerShell\Modules. I tried removing the additional PowerShell modules I had previously downloaded that were located in C:\Program Files\WindowsPowerShell\Modules (even though everything was working previously) but had no luck.

I'm not sure how I would go about repairing my broken DLL (and I really would like to avoid reseting my PC if I can). I can provide my CBS.log to you through email if you think that might help.

Eugeny commented 3 years ago

If your PS 5.1 DLLs are damaged, you can only replace them with identical ones from another Windows machine. For PS6+, you can just reinstall PowerShell itself. Just to reiterate, none of this has anything to do with Terminus itself, which by default installs into a self-contained directory in %APPDATA% without administrative permissions.

mondash commented 3 years ago

It does look like installing this shouldn't have caused this problem. I'm not sure why installing this happened to (directly or indirectly) result in this issue. I'll see if I can replace my bad DLL with a copy from a different machine since I'm using 5.1. If I can get it working again after doing that, I'll close this issue.

I'll note again here that I also discovered that the uninstaller left me with dirty values in my registry. The explorer context menu still showed up after uninstalling, and I had to manually remove the registry entries.

mondash commented 3 years ago

Probably final update here. Unfortunately I was never able to resolve my issue with PowerShell 5.1, and since I've spent the better part of a week trying to resolve (even copying a fresh copy of the WindowsPowerShell directry from Windows 10 VM), I'm just gonna give up for now. I've installed the latest (7.1.2) version of PowerShell Core, and that seems to be working.

While I'm still not sure whether installing Terminus directly caused my problem, I still don't think I can rule it out since it would have to be a heck of a coincidence for my PowerShell to break directly after installing. Maybe one day when I want to clean up my computer I'll do a full reset and be able to use standard PowerShell again.

Moral of the story is make FREQUENT backups.

@Eugeny Thank you greatly for your assistance debugging. I'm still a bit sad I could not find a solution, but I am glad I found a workaround for now. I'll leave this issue open for you to close. There is still the bit about dirty registry entries that has not been resolved, but you'll probably just want to close this issue and make a new one for that. I wish you the best. Perhaps I'll try Terminus another time (it does look pretty cool 😎 ).

cjerrington commented 3 years ago

Just by looking at the error, it might be an issue with Posh-Git Module not Terminus.

C:\Program Files\WindowsPowerShell\Modules\posh-git\1.0.0\Utils.ps1

Might try uninstalling Posh-Git and reinstalling. Does Powershell work in the default Powershell.exe application?

mondash commented 3 years ago

@cjerrington PowerShell does not work in the default Powershell.exe application.

I've already tried removing all additional modules that I had installed (posh-git, Get-ChildItemColor, oh-my-posh). I don't think this error has anything to do with posh-git though. If you take a look closer at the last error in the description of this issue, you can see the core problem that I discovered.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in two weeks unless you comment. Thank you for your contributions.