fix(powershell): execution policy check breaks when run in pwsh

When topgrade is run from within pwsh, the execution policy check breaks
for the Windows Update and Windows Store steps, because they use normal
powershell and the inherited PSModulePath environment variable breaks
the Microsoft.PowerShell.Security module import. So we unset that
variable to fix the issue, but also allow for those steps to use pwsh as
neither step actually requires PowerShell 5.

Co-authored-by: nistee <52573120+niStee@users.noreply.github.com>
This commit is contained in:
Andre Toerien
2025-06-22 15:39:50 +02:00
committed by Gideon
parent 9fc5fe9798
commit f78514dbd8
4 changed files with 33 additions and 31 deletions

View File

@@ -7,7 +7,6 @@ use tracing::debug;
use crate::command::CommandExt;
use crate::execution_context::ExecutionContext;
use crate::powershell;
use crate::step::Step;
use crate::terminal::{print_separator, print_warning};
use crate::utils::{require, which};
@@ -226,7 +225,7 @@ pub fn run_wsl_topgrade(ctx: &ExecutionContext) -> Result<()> {
}
pub fn windows_update(ctx: &ExecutionContext) -> Result<()> {
let powershell = powershell::Powershell::windows_powershell();
let powershell = ctx.powershell();
print_separator(t!("Windows Update"));
@@ -244,7 +243,7 @@ pub fn windows_update(ctx: &ExecutionContext) -> Result<()> {
}
pub fn microsoft_store(ctx: &ExecutionContext) -> Result<()> {
let powershell = powershell::Powershell::windows_powershell();
let powershell = ctx.powershell();
print_separator(t!("Microsoft Store"));