Howto initiate Windows Update on server core from a PS remote session

powershell-v4.0remote-accesswindows-server-2012-r2windows-update

When I am logged in via remote desktop on a Windows Server 2012 R2 Core machine I can trigger the windows update by running sconfig.cmd. This however fails when its getting called within a PS remote session:

Enter-PSSession -ComputerName server2

This is what sconfig complains about. It basically says that it can't find a specific registry value. A funny thing to note is that Microsoft choose VBScript over PowerShell to program this CLI interface…

[server2]: PS C:\> sconfig

C:\>echo off
sconfig : FEHLER: Der angegebene Registrierungsschl?ssel bzw. Wert wurde nicht gefunden.
    + CategoryInfo          : NotSpecified: (FEHLER: Der ang...nicht gefunden.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

Microsoft (R) Windows Script Host, Version 5.8
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

System wird ?berpr?ft...

[...]

14) Server herunterfahren
15) Zur Befehlszeile wechseln

C:\Windows\System32\de-DE\sconfig.vbs(326, 1) Laufzeitfehler in Microsoft VBScript: Eingabe hinter Dateiende.

How should/can I initiate a Windows Update when being logged in via PS remote session?

Best Answer

You can't actually trigger that directly over winrm/winrs.

A somewhat popular powershell module (PSWindowsUpdate) for performing Windows Updates from Powershell exists, and to perform updates on a remote system it actually copies the module to the remote system and schedules a new one-time task on the remote system.

In the invoke-WUInstall.ps1 file it has this comment about remotely triggering an update.

Use Invoke-WUInstall to invoke Windows Update install remotly. It Based on TaskScheduler because CreateUpdateDownloader() and CreateUpdateInstaller() methods can't be called from a remote computer - E_ACCESSDENIED.