Skip to content
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

Windows system update fails #531

Open
2 of 6 tasks
selfagency opened this issue Jul 31, 2023 · 4 comments
Open
2 of 6 tasks

Windows system update fails #531

selfagency opened this issue Jul 31, 2023 · 4 comments
Labels
C-bug Something isn't working P-Windows Windows issue

Comments

@selfagency
Copy link

Erroneous Behavior

Import-Module : File
C:\Users\dsieradski\OneDrive\Documents\PowerShell\Modules\PSWindowsUpdate\2.2.0.3\PSWindowsUpdate.psm1 cannot be
loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ Import-Module PSWindowsUpdate; Install-WindowsUpdate -MicrosoftUpdate ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [Import-Module], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess,Microsoft.PowerShell.Commands.ImportModuleCommand
Install-WindowsUpdate : The 'Install-WindowsUpdate' command was found in the module 'PSWindowsUpdate', but the
module could not be loaded. For more information, run 'Import-Module PSWindowsUpdate'.
At line:1 char:32
+ Import-Module PSWindowsUpdate; Install-WindowsUpdate -MicrosoftUpdate ...
+                                ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Install-WindowsUpdate:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

Windows update failed:
   0: Command failed: `C:\windows\System32\WindowsPowerShell\v1.0\powershell.EXE -NoProfile -Command 'Import-Module PSWindowsUpdate; Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -Verbose'`
   1: `C:\windows\System32\WindowsPowerShell\v1.0\powershell.EXE` failed: exit code: 1

Expected Behavior

For the update to run as expected.

Steps to reproduce

topgrade --only system

Possible Cause (Optional)

C:\windows\System32\WindowsPowerShell\v1.0\powershell.EXE is a restricted and outdated version of PowerShell. You should use pwsh instead, which is the modern version, if it's available and present in the path.

Problem persists without calling from topgrade

  • Yes
  • No

Did you run topgrade through Remote Execution

  • Yes
  • No

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

  • Yes
  • No

Additional Details

  • Operation System/Version
    Windows 10 Education 22H2

  • Installation
    Cargo

  • Topgrade version (topgrade -V)
    12.0.2

Verbose Output (topgrade -v)

❯ topgrade -v --only system
DEBUG Configuration at C:\Users\dsieradski\AppData\Roaming\topgrade.toml
DEBUG No include paths found in C:\Users\dsieradski\AppData\Roaming\topgrade.toml
DEBUG Loaded configuration: ConfigFile { include: Some(Include { paths: None }), misc: Some(Misc { pre_sudo: None, sudo_command: None, git_repos: None, predefined_git_repos: None, disable: None, ignore_failures: None, remote_topgrades: None, remote_topgrade_path: None, ssh_arguments: None, git_arguments: None, tmux_arguments: None, set_title: None, display_time: None, assume_yes: Some(true), yay_arguments: None, aura_aur_arguments: None, aura_pacman_arguments: None, no_retry: None, run_in_tmux: None, cleanup: None, notify_each_step: None, accept_all_windows_updates: None, skip_notify: None, bashit_branch: None, only: None, no_self_update: None }), pre_commands: Some({}), post_commands: Some({}), commands: Some({}), python: Some(Python { enable_pip_review: None, enable_pip_review_local: None, enable_pipupgrade: None, pipupgrade_arguments: None }), composer: Some(Composer { self_update: None }), brew: Some(Brew { greedy_cask: None, autoremove: 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, apt_arguments: None, enable_tlmgr: None, redhat_distro_sync: None, suse_dup: None, rpm_ostree: None, emerge_sync_flags: None, emerge_update_flags: None, home_manager_arguments: None }), git: Some(Git { max_concurrency: None, arguments: None, repos: None, pull_predefined: None }), windows: Some(Windows { accept_all_updates: None, self_rename: None, open_remotes_in_new_terminal: None, enable_winget: Some(true), wsl_update_pre_release: None, wsl_update_use_web_download: None }), npm: Some(NPM { use_sudo: None }), yarn: Some(Yarn { use_sudo: 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 }), distrobox: Some(Distrobox { use_root: None, containers: None }) }
DEBUG Version: 12.0.2
DEBUG OS: x86_64-pc-windows-msvc
DEBUG Args { inner: ["C:\\Users\\dsieradski\\scoop\\apps\\topgrade\\current\\topgrade.exe", "-v", "--only", "system"] }
DEBUG Binary path: Ok("C:\\Users\\dsieradski\\scoop\\apps\\topgrade\\current\\topgrade.exe")
DEBUG Self Update: true
DEBUG Detected "C:\\Program Files\\Git\\cmd\\git.EXE" as "git"
DEBUG Detected "C:\\Program Files\\PowerShell\\7\\pwsh.EXE" as "pwsh"
DEBUG Executing command `C:\Program Files\PowerShell\7\pwsh.EXE -NoProfile -Command 'Split-Path $profile'`
DEBUG Path "C:\\Users\\dsieradski\\OneDrive\\Documents\\PowerShell" exists
DEBUG Path "C:\\Users\\dsieradski\\AppData\\Roaming\\.emacs.d" doesn't exist
DEBUG Cannot find "doas"
DEBUG Cannot find "please"
DEBUG Cannot find "sudo"
DEBUG Cannot find "gsudo"
DEBUG Cannot find "pkexec"

── 09:05:30 - Self update ──────────────────────────────────────────────────────
DEBUG starting new connection: https://api.github.com/
DEBUG resolving host="api.github.com"
DEBUG connecting to 140.82.114.6:443
DEBUG connected to 140.82.114.6:443
DEBUG No cached session for DnsName("api.github.com")
DEBUG Not resuming any session
DEBUG Using ciphersuite TLS13_AES_128_GCM_SHA256
DEBUG Not resuming
DEBUG TLS1.3 encrypted extensions: [ServerNameAck, Protocols([ProtocolName(6832)])]
DEBUG ALPN protocol is Some(b"h2")
DEBUG binding client connection
DEBUG client connection bound
DEBUG send frame=Settings { flags: (0x0), enable_push: 0, initial_window_size: 2097152, max_frame_size: 16384 }
DEBUG Connection{peer=Client}: new
DEBUG Connection{peer=Client}: send frame=WindowUpdate { stream_id: StreamId(0), size_increment: 5177345 }
DEBUG pooling idle connection for ("https", api.github.com)
DEBUG Connection{peer=Client}: send frame=Headers { stream_id: StreamId(1), flags: (0x5: END_HEADERS | END_STREAM) }
DEBUG Connection{peer=Client}: received frame=Settings { flags: (0x0), max_concurrent_streams: 100, initial_window_size: 67108864, max_frame_size: 65536, enable_connect_protocol: 1 }
DEBUG Connection{peer=Client}: send frame=Settings { flags: (0x1: ACK) }
DEBUG Connection{peer=Client}: received frame=Settings { flags: (0x1: ACK) }
DEBUG Connection{peer=Client}: received settings ACK; applying Settings { flags: (0x0), enable_push: 0, initial_window_size: 2097152, max_frame_size: 16384 }
DEBUG Connection{peer=Client}: received frame=Headers { stream_id: StreamId(1), flags: (0x4: END_HEADERS) }
DEBUG Connection{peer=Client}: received frame=Data { stream_id: StreamId(1) }
DEBUG Connection{peer=Client}: received frame=Data { stream_id: StreamId(1), flags: (0x1: END_STREAM) }
DEBUG Connection{peer=Client}: close
Topgrade is up-to-date
DEBUG Step "Windows update"
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 'Get-Module -ListAvailable PSWindowsUpdate'`

── 09:05:41 - Windows Update ───────────────────────────────────────────────────
DEBUG Executing command `C:\windows\System32\WindowsPowerShell\v1.0\powershell.EXE -NoProfile -Command 'Import-Module PSWindowsUpdate; Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -Verbose'`
Import-Module : File
C:\Users\dsieradski\OneDrive\Documents\PowerShell\Modules\PSWindowsUpdate\2.2.0.3\PSWindowsUpdate.psm1 cannot be
loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at
https:/go.microsoft.com/fwlink/?LinkID=135170.
At line:1 char:1
+ Import-Module PSWindowsUpdate; Install-WindowsUpdate -MicrosoftUpdate ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [Import-Module], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess,Microsoft.PowerShell.Commands.ImportModuleCommand
Install-WindowsUpdate : The 'Install-WindowsUpdate' command was found in the module 'PSWindowsUpdate', but the
module could not be loaded. For more information, run 'Import-Module PSWindowsUpdate'.
At line:1 char:32
+ Import-Module PSWindowsUpdate; Install-WindowsUpdate -MicrosoftUpdate ...
+                                ~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Install-WindowsUpdate:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CouldNotAutoloadMatchingModule

DEBUG Command failed: Err(
   0: Command failed: `C:\windows\System32\WindowsPowerShell\v1.0\powershell.EXE -NoProfile -Command 'Import-Module PSWindowsUpdate; Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -Verbose'`
   1: `C:\windows\System32\WindowsPowerShell\v1.0\powershell.EXE` failed: exit code: 1

Location:
   src\steps\powershell.rs:122

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.)
DEBUG Step "Windows update" failed:
   0: Command failed: `C:\windows\System32\WindowsPowerShell\v1.0\powershell.EXE -NoProfile -Command 'Import-Module PSWindowsUpdate; Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -Verbose'`
   1: `C:\windows\System32\WindowsPowerShell\v1.0\powershell.EXE` failed: exit code: 1

Location:
   src\steps\powershell.rs:122

Backtrace omitted. Run with RUST_BACKTRACE=1 environment variable to display it.
Run with RUST_BACKTRACE=full to include source snippets.
Windows update failed:
   0: Command failed: `C:\windows\System32\WindowsPowerShell\v1.0\powershell.EXE -NoProfile -Command 'Import-Module PSWindowsUpdate; Install-WindowsUpdate -MicrosoftUpdate -AcceptAll -Verbose'`
   1: `C:\windows\System32\WindowsPowerShell\v1.0\powershell.EXE` failed: exit code: 1

Location:
   src\steps\powershell.rs:122
@selfagency selfagency added the C-bug Something isn't working label Jul 31, 2023
@selfagency
Copy link
Author

As I suspected, when run with pwsh instead of Windows PowerShell 1.0, it works.

@selfagency
Copy link
Author

Found a workaround. Open Windows PowerShell as administrator and run set-executionpolicy remotesigned from the prompt.

@SteveLauC SteveLauC added the P-Windows Windows issue label Oct 27, 2023
@niStee
Copy link
Contributor

niStee commented Feb 11, 2024

@selfagency, in #671 an evaluated shell is called to import and run the PSWindowsUpdate module. Let me know if this solves your problem.

@niStee
Copy link
Contributor

niStee commented Jul 31, 2024

#842

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Something isn't working P-Windows Windows issue
Projects
None yet
Development

No branches or pull requests

3 participants