8

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?

  • 2
    I don't read German, but is that a Permissions/access denied message? Fact of the matter is that it's a huge pain to install Windows Updates remotely without something like SCCM or WSUS. Every method I've seen, that actually works, relies on PSexec (or similar) to execute the command locally, but from a remote computer. I think I end up using WuInstall or BatchPatch when I need to do this sort of thing, without SCCM. There are also some PowerShell modules on Technet for this kind of thing that might be of use, by my experience with them has been very hit-or-miss. Mostly miss. – HopelessN00b Nov 19 '14 at 19:59
  • 3
    Oh, almost forgot. The best free, non-trial/freemium app I've seen for remotely installing Windows Updates without SCCM/WSUS/etc. is PoshPAIG, and The Scripting Guy has a blog article about it you might want to check out. It's not exactly what you're looking for, but it's as close as you'll get without rolling your own. – HopelessN00b Nov 19 '14 at 20:07
  • Basically a dup of serverfault.com/questions/336705/… – Zoredache Nov 19 '14 at 20:43
  • @Zoredache But the answers there suck. Yours is much better, and I wouldn't vote to dupe close this on that basis alone. – HopelessN00b Nov 19 '14 at 21:13
7

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

A somewhat popular powershell module 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.

1

All hail to the poster of the last comment. It works.

Get the pswidowsupdate files from the web & unzip them. Then import the module & run this code (the invoke-wsuinstall.ps1 file has the sample code but I removed a bit from it and it still works):

$Script = {Get-WUInstall -AcceptAll -AutoReboot | Out-File C:\PSWindowsUpdate.log}
Invoke-WUInstall -ComputerName computername -Script $Script
Get-Content \ \ computername\c$\PSWindowsUpdate.log

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.