mgajda83 / PSWindowsUpdate

This module contain cmdlets to manage Windows Update Client.
MIT License
253 stars 24 forks source link

SSH oneliner to check status #25

Open patch-work opened 4 weeks ago

patch-work commented 4 weeks ago
> ssh 192.168.1.15
PC> powershell -nologo -noprofile
PS> Get-WindowsUpdate -RootCategories 'Critical Updates', 'Security Updates', 'Definition Updates'

ComputerName Status     KB          Size Title
------------ ------     --          ---- -----
PC           -------    KB2267602 1021MB Security Intelligence Update for Microsoft Defender Antivirus - KB2267602 (Version 1.413.637.0) - Current Channel (Broad)

So far so good.

PS> exit
PC> powershell -nologo -noprofile -command "Get-WindowsUpdate -RootCategories 'Critical Updates', 'Security Updates', 'Definition Updates'"

ComputerName Status     KB          Size Title
------------ ------     --          ---- -----
PC           -------    KB2267602 1021MB Security Intelligence Update for Microsoft Defender Antivirus - KB2267602 (Version 1.413.637.0) - Current Channel (Broad)c

Happy again.

PC> exit
> ssh 192.168.1.15 powershell -nologo -noprofile -command "Get-WindowsUpdate -RootCategories 'Critical Updates', 'Security Updates', 'Definition Updates'"
Get-WindowsUpdate : Win32 internal error "Access is denied" 0x5 occurred while reading the console output buffer.
Contact Microsoft Customer Support Services.
At line:1 char:1
+ Get-WindowsUpdate -RootCategories 'Critical Updates', 'Security Updat ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ReadError: (:) [Get-WindowsUpdate], HostException
+ FullyQualifiedErrorId : ReadConsoleOutput,PSWindowsUpdate.GetWindowsUpdate

Not happy.

[...]
PS> get-help Invoke-WUJob
[...]
DESCRIPTION
Use Invoke-WUJobs cmdlet to invoke PSWindowsUpdate actions remot[e]ly. 
It [is] [b]ased on TaskScheduler because CreateUpdateDownloader() and 
CreateUpdateInstaller() methods can't be called from a remote computer - E_ACCESSDENIED.

Note: Because we do not have the ability to interact, is recommended use -AcceptAll for Install-WindowsUpdate.

Will it work with Get-WindowsUpdate?

PS> invoke-WUJob -Script { Get-WindowsUpdate -Verbose -RootCategories 'Critical Updates', 'Security Updates', 'Definition Updates' } -Verbose -RunNow -Confirm:$false
VERBOSE: Performing the operation "(7/1/2024 10:16:29 PM) Invoke WU job: powershell.exe -Command " Get-WindowsUpdate -Verbose -RootCategories 'Critical Updates', 'Security Updates', 'Definition Updates' "" on target "PC".
VERBOSE: Try to connect PC. Test 1
VERBOSE: Try to connect PC. Test 2
VERBOSE: Try to connect PC. Test 3
VERBOSE: Registering task: PSWindowsUpdate
VERBOSE: Starting task: PSWindowsUpdate

No output.

Is "Invoke-WUJob" limited to installations?

patch-work commented 2 weeks ago

The problem is caused by a Windows setting, because it does not appear on other computers with the same OS.