webinstall / webi-installers

Primary and community-submitted packages for webinstall.dev
https://webinstall.dev
Mozilla Public License 2.0
1.75k stars 187 forks source link

[Bug] fails in PowerShell Core 7.x (but works in PowerShell Classic 5.x) #832

Open michaelgracious opened 3 months ago

michaelgracious commented 3 months ago

What were you trying to install (or what else went wrong)?

installing/updating ANY webi package

What exactly did you do?

Running webi webi for instance

What went wrong?

Running the this command using Windows Terminal (running powershell 7.4.1 or 7.5 preview) results in an error (any installer fails, just using webi webi as an example)

Set-ExecutionPolicy : The 'Set-ExecutionPolicy' command was found in the module 'Microsoft.PowerShell.Security', but
the module could not be loaded. For more information, run 'Import-Module Microsoft.PowerShell.Security'.
At C:\Users\thul\.local\tmp\webi.install.ps1:7 char:1
+ Set-ExecutionPolicy -Scope Process Bypass
+ ~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Set-ExecutionPolicy:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

Windows Terminal is running version 1.20.10822.0

Might be related to https://github.com/PowerShell/PowerShell/issues/18530 ?

Which OS did you try on?

What type of computer (i.e. laptop, desktop, Raspberry Pi)?

coolaj86 commented 2 months ago

Are you on a restricted user account? What version of Windows, PowerShell (powershell --version), and PowerShell Core (pwsh --version) do you have?

michaelgracious commented 2 months ago
  1. User account is not restricted, i tried both admin privileged shell and normal shell
  2. As i stated in the issue im on Powershell 7.4.1
  3. Powershell core is 7.4 (i need to double check as im not at home now)
coolaj86 commented 2 months ago

Dusting off my Windows computer...

I can confirm in PowerShell Core 7.3.9 that running webi exits immediately - but I don't even get an error message of any kind.

I suppose that if I update from Windows 10.0.22000 (which is actually Windows 11) to the current version, I will probably be plagued with the same problem in PowerShell (native).

Perhaps I could add a try around Import-Module Microsoft.PowerShell.Security and see if it works forwards and backwards.

coolaj86 commented 2 months ago

@jkunkee Any idea how users can run scripts with the new PowerShell permission system?

coolaj86 commented 2 months ago

@michaelgracious What do you get for the output of this?

Get-ExecutionPolicy -List

I always thought it was stupid that for a script to get permissions to run, all it had to do was literally give itself permission to run as the first thing it did when it was running... but if they "fixed" that, well, then I don't think you can get scripts to run without going into admin settings.

Will you also try this?

Set-ExecutionPolicy -Scope Process Bypass
webi --help
webi webi

Meanwhile... I run upgrades...

coolaj86 commented 1 month ago

@michaelgracious I've finished updating Windows 11 ARM and it only brought my native PowerShell to 5.1.x, and Webi still works in that.

So it looks like PowerShell Core can't call out to powershell classic.

I think we may run into a problem where we have to detect whether it's PowerShell Classic or PowerShell Core...

coolaj86 commented 1 month ago

Some more notes:

From https://github.com/webinstall/webi-installers/blob/7b70ab85380727919ae43b986a37a90cf832572c/webi/webi-pwsh.ps1#L136

~/.local/bin/webi.bat:

@echo off
powershell -ExecutionPolicy Bypass -File "%USERPROFILE%\.local\bin\webi-pwsh.ps1" %*