Skip to content

Windows Update fails with old Powershell (v1, powershell.exe), works with new (v7, pwsh.exe) #1579

@reini-1

Description

@reini-1

Checklist

  • I have searched the issue tracker for relevant or duplicate issues.

Erroneous Behavior

$ topgrade --only system --verbose
DEBUG Current system locale is de-DE
DEBUG Configuration at C:\Users\reini\AppData\Roaming\topgrade.toml
DEBUG Loaded configuration: ConfigFile { include: Some(Include { paths: None }), misc: Some(Misc { allow_root: None, pre_sudo: None, sudo_command: None, disable: None, ignore_failures: None, remote_topgrades: None, remote_topgrade_path: None, ssh_arguments: None, tmux_arguments: None, set_title: None, display_time: None, assume_yes: None, no_retry: None, show_skipped: None, run_in_tmux: None, tmux_session_mode: None, cleanup: None, notify_each_step: None, skip_notify: None, bashit_branch: None, only: None, no_self_update: None, log_filters: None, show_distribution_summary: None }), pre_commands: Some({}), post_commands: Some({}), commands: Some({}), conda: Some(Conda { env_names: None, env_paths: None }), python: Some(Python { enable_pip_review: None, enable_pip_review_local: None, enable_pipupgrade: None, pipupgrade_arguments: None, poetry_force_self_update: None }), composer: Some(Composer { self_update: None }), brew: Some(Brew { greedy_cask: None, greedy_latest: None, greedy_auto_updates: None, autoremove: None, fetch_head: None }), linux: Some(Linux { yay_arguments: None, aura_aur_arguments: None, aura_pacman_arguments: None, arch_package_manager: None, show_arch_news: None, garuda_update_arguments: None, trizen_arguments: None, pikaur_arguments: None, pamac_arguments: None, dnf_arguments: None, nix_arguments: None, nix_env_arguments: None, apt_arguments: None, enable_tlmgr: None, redhat_distro_sync: None, suse_dup: None, rpm_ostree: None, bootc: None, emerge_sync_flags: None, emerge_update_flags: None, home_manager_arguments: None }), mandb: Some(Mandb { enable: None }), git: Some(Git { max_concurrency: None, arguments: None, repos: None, pull_predefined: None, fetch_only: None }), containers: Some(Containers { ignored_containers: None, runtime: None, system_prune: None }), windows: Some(Windows { accept_all_updates: None, updates_auto_reboot: None, self_rename: None, open_remotes_in_new_terminal: None, wsl_update_pre_release: None, wsl_update_use_web_download: None, winget_silent_install: None, winget_use_sudo: None }), npm: Some(NPM { use_sudo: None }), chezmoi: Some(Chezmoi { exclude_encrypted: None }), mise: Some(Mise { bump: None, interactive: None, jobs: None }), yarn: Some(Yarn { use_sudo: None }), deno: Some(Deno { version: None }), vim: Some(Vim { force_plug_update: None }), firmware: Some(Firmware { upgrade: None }), vagrant: Some(Vagrant { directories: None, power_on: None, always_suspend: None }), flatpak: Some(Flatpak { use_sudo: None }), pixi: Some(Pixi { include_release_notes: None }), distrobox: Some(Distrobox { use_root: None, containers: None }), lensfun: Some(Lensfun { use_sudo: None }), julia: Some(JuliaConfig { startup_file: None }), zigup: Some(Zigup { target_versions: None, install_dir: None, path_link: None, cleanup: None }), vscode: Some(VscodeConfig { profile: None }), doom: Some(DoomConfig { aot: None }), rustup: Some(Rustup { channels: None }), pkgfile: Some(Pkgfile { enable: None }) }
DEBUG Version: 16.6.0
DEBUG OS: x86_64-pc-windows-msvc
DEBUG Args { inner: ["C:\\Users\\reini\\AppData\\Local\\Microsoft\\WinGet\\Packages\\topgrade-rs.topgrade_Microsoft.Winget.Source_8wekyb3d8bbwe\\topgrade.exe", "--only", "system", "--verbose"] }
DEBUG Binary path: Ok("C:\\Users\\reini\\AppData\\Local\\Microsoft\\WinGet\\Packages\\topgrade-rs.topgrade_Microsoft.Winget.Source_8wekyb3d8bbwe\\topgrade.exe")
DEBUG self-update Feature Enabled: true
DEBUG Configuration: Config { opt: CommandLineArgs { edit_config: false, show_config_reference: false, run_in_tmux: false, no_tmux: false, cleanup: false, dry_run: false, run_type: Wet, no_retry: false, disable: [], only: [System], custom_commands: [], env: [], verbose: true, keep_at_end: false, skip_notify: false, yes: None, disable_predefined_git_repos: false, config: None, remote_host_limit: None, show_skipped: false, allow_root: false, log_filter: "warn", gen_completion: None, gen_manpage: false, no_self_update: false }, config_file: ConfigFile { include: Some(Include { paths: None }), misc: Some(Misc { allow_root: None, pre_sudo: None, sudo_command: None, disable: None, ignore_failures: None, remote_topgrades: None, remote_topgrade_path: None, ssh_arguments: None, tmux_arguments: None, set_title: None, display_time: None, assume_yes: None, no_retry: None, show_skipped: None, run_in_tmux: None, tmux_session_mode: None, cleanup: None, notify_each_step: None, skip_notify: None, bashit_branch: None, only: None, no_self_update: None, log_filters: None, show_distribution_summary: None }), pre_commands: Some({}), post_commands: Some({}), commands: Some({}), conda: Some(Conda { env_names: None, env_paths: None }), python: Some(Python { enable_pip_review: None, enable_pip_review_local: None, enable_pipupgrade: None, pipupgrade_arguments: None, poetry_force_self_update: None }), composer: Some(Composer { self_update: None }), brew: Some(Brew { greedy_cask: None, greedy_latest: None, greedy_auto_updates: None, autoremove: None, fetch_head: None }), linux: Some(Linux { yay_arguments: None, aura_aur_arguments: None, aura_pacman_arguments: None, arch_package_manager: None, show_arch_news: None, garuda_update_arguments: None, trizen_arguments: None, pikaur_arguments: None, pamac_arguments: None, dnf_arguments: None, nix_arguments: None, nix_env_arguments: None, apt_arguments: None, enable_tlmgr: None, redhat_distro_sync: None, suse_dup: None, rpm_ostree: None, bootc: None, emerge_sync_flags: None, emerge_update_flags: None, home_manager_arguments: None }), mandb: Some(Mandb { enable: None }), git: Some(Git { max_concurrency: None, arguments: None, repos: None, pull_predefined: None, fetch_only: None }), containers: Some(Containers { ignored_containers: None, runtime: None, system_prune: None }), windows: Some(Windows { accept_all_updates: None, updates_auto_reboot: None, self_rename: None, open_remotes_in_new_terminal: None, wsl_update_pre_release: None, wsl_update_use_web_download: None, winget_silent_install: None, winget_use_sudo: None }), npm: Some(NPM { use_sudo: None }), chezmoi: Some(Chezmoi { exclude_encrypted: None }), mise: Some(Mise { bump: None, interactive: None, jobs: None }), yarn: Some(Yarn { use_sudo: None }), deno: Some(Deno { version: None }), vim: Some(Vim { force_plug_update: None }), firmware: Some(Firmware { upgrade: None }), vagrant: Some(Vagrant { directories: None, power_on: None, always_suspend: None }), flatpak: Some(Flatpak { use_sudo: None }), pixi: Some(Pixi { include_release_notes: None }), distrobox: Some(Distrobox { use_root: None, containers: None }), lensfun: Some(Lensfun { use_sudo: None }), julia: Some(JuliaConfig { startup_file: None }), zigup: Some(Zigup { target_versions: None, install_dir: None, path_link: None, cleanup: None }), vscode: Some(VscodeConfig { profile: None }), doom: Some(DoomConfig { aot: None }), rustup: Some(Rustup { channels: None }), pkgfile: Some(Pkgfile { enable: None }) }, allowed_steps: [System] }
DEBUG Detected "C:\\Program Files\\gsudo\\Current\\gsudo.exe" as "gsudo"
DEBUG Sudo: Ok(Sudo { path: Some("C:\\Program Files\\gsudo\\Current\\gsudo.exe"), kind: Gsudo })
DEBUG Step "Windows update"
DEBUG Cannot find "pwsh"
DEBUG Detected "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" as "powershell"
DEBUG Executing command `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -Command 'Split-Path $PROFILE'`
DEBUG Path "C:\\Users\\reini\\OneDrive\\Documents\\WindowsPowerShell" exists
DEBUG Found PowerShell profile: Some("C:\\Users\\reini\\OneDrive\\Documents\\WindowsPowerShell")

── 11:37:22 - Windows-Update ───────────────────────────────────────────────────
DEBUG Executing command `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -Command 'Get-Module -ListAvailable PSWindowsUpdate'`
DEBUG Executing command `C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NoProfile -Command Get-ExecutionPolicy`
DEBUG Found PowerShell ExecutionPolicy: Ok("RemoteSigned")
DEBUG Executing command `C:\Program Files\gsudo\Current\gsudo.exe -d 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' -NoProfile -Command 'Import-Module PSWindowsUpdate; Install-WindowsUpdate -Verbose -AcceptAll -IgnoreReboot'`
Import-Module : Das angegebene Modul "PSWindowsUpdate" wurde nicht geladen, da in keinem Modulverzeichnis eine gültige Moduldatei gefunden wurde.
In Zeile:1 Zeichen:1
+ Import-Module PSWindowsUpdate; Install-WindowsUpdate -Verbose -Accept ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ResourceUnavailable: (PSWindowsUpdate:String) [Import-Module], FileNotFoundException
    + FullyQualifiedErrorId : Modules_ModuleNotFound,Microsoft.PowerShell.Commands.ImportModuleCommand

Install-WindowsUpdate : Die Benennung "Install-WindowsUpdate" wurde nicht als Name eines Cmdlet, einer Funktion, einer Skriptdatei oder eines
ausführbaren Programms erkannt. Überprüfen Sie die Schreibweise des Namens, oder ob der Pfad korrekt ist (sofern enthalten), und wiederholen Sie den
Vorgang.
In Zeile:1 Zeichen:32
+ Import-Module PSWindowsUpdate; Install-WindowsUpdate -Verbose -Accept ...
+                                ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Install-WindowsUpdate:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

DEBUG Command failed: Err(
   0: \x1b[91mCommand failed: `C:\Program Files\gsudo\Current\gsudo.exe -d 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' -NoProfile -Command 'Import-Module PSWindowsUpdate; Install-WindowsUpdate -Verbose -AcceptAll -IgnoreReboot'`\x1b[0m
   1: \x1b[91m`C:\Program Files\gsudo\Current\gsudo.exe` fehlgeschlagen: exit code: 1\x1b[0m

Location:
   \x1b[35msrc\steps\os\windows.rs\x1b[0m:\x1b[35m235\x1b[0m)
DEBUG Step "Windows update" failed:
   0: \x1b[91mCommand failed: `C:\Program Files\gsudo\Current\gsudo.exe -d 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' -NoProfile -Command 'Import-Module PSWindowsUpdate; Install-WindowsUpdate -Verbose -AcceptAll -IgnoreReboot'`\x1b[0m
   1: \x1b[91m`C:\Program Files\gsudo\Current\gsudo.exe` fehlgeschlagen: exit code: 1\x1b[0m

Location:
   \x1b[35msrc\steps\os\windows.rs\x1b[0m:\x1b[35m235\x1b[0m
Windows update fehlgeschlagen:
   0: Command failed: `C:\Program Files\gsudo\Current\gsudo.exe -d 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' -NoProfile -Command 'Import-Module PSWindowsUpdate; Install-WindowsUpdate -Verbose -AcceptAll -IgnoreReboot'`
   1: `C:\Program Files\gsudo\Current\gsudo.exe` fehlgeschlagen: exit code: 1

Location:
   src\steps\os\windows.rs:235
Wiederholen? (y) Ja / (n) Nein / (s) Shell / (q) Beenden

── 11:37:50 - Zusammenfassung ──────────────────────────────────────────────────
Windows update: FEHLGESCHLAGEN
DEBUG Desktop notification: Topgrade wurde mit Fehlern beendet

Expected Behavior

$ &"C:\Program Files\gsudo\Current\gsudo.exe" -d 'C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe' -NoProfile -Command 'Import-Module PSWindowsUpdate; Install-WindowsUpdate -Verbose -AcceptAll -IgnoreReboot'
AUSFÜHRLICH: XXXX (01.12.2025 11:25:41): Connecting to Microsoft Update server. Please wait...
AUSFÜHRLICH: Found [0] Updates in pre search criteria

Steps to reproduce

Run topgrade --only system as a non-admin user, gsudo.exe installed system-wide, Module PSWindowsUpdate installed and without configuration file (default configuration file).
Admin user to escalate privileges to.

Possible Cause (Optional)

Maybe path with spaces to gsudu is a problem, or gsudo is not proper called.
A manual call from a shell works, see expected behaviour.

Problem persists without calling from topgrade

  • Yes
  • No

Ran through Remote Execution

  • Yes
  • No

If yes, does the issue still occur when you run topgrade directly in your
remote host?

  • Yes
  • No

Configuration file (Optional)

No configuration file == default configuration file

Additional Details

  • Operation System/Version

cmd /c ver

Microsoft Windows [Version 10.0.26200.7171]

  • Installation

winget.exe install --id "topgrade-rs.topgrade"

  • Topgrade version (topgrade -V)
    topgrade --version
    topgrade 16.6.0

Verbose Output (topgrade -v)

see above


Metadata

Metadata

Assignees

No one assigned

    Labels

    P-WindowsWindows issuehelp wantedExtra attention is neededneeds informationMore information is required from the reporter

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions