bklockwood / PSWU

PowerShell Windows Update. CLI/scripted windows updates!
MIT License
24 stars 2 forks source link

Make it remoteable #3

Closed bklockwood closed 8 years ago

bklockwood commented 9 years ago

Core functions need to be remoteable. That is, if I am sitting at LocalPC, should be able to do this:

PS>Get-UpdateList -Computername RemotePC 

PC       KB      T H D R E MB  Severity Published  Title                                   
-------- --      - - - - - --  -------- ---------  -----                                   
RemotePC 3109599 S - D - E 124          11/18/2015 Lang Pack (Language Features) Feature...
RemotePC 3119147 S - D - E 18           12/8/2015  Security Update for Internet Explorer...
RemotePC 890830  S - D - E 57           12/8/2015  Windows Malicious Software Removal To...
RemotePC 3124200 S - D - E 300          12/17/2015 Cumulative Update for Windows 10 Vers...
RemotePC 2267602 S - D - E 443          12/20/2015 Definition Update for Windows Defende...
bklockwood commented 9 years ago

Tentative plan:

  1. Make PSWU a module (rename the MAIN function to 'install-allupdates')
  2. install-allupdates, if invoked with a -computername param not equal to $env:COMPUTERNAME, ".", or "localhost", start a session to the remote machine, then use implicit remoting to 'borrow' the module from the computer on which PSWU was invoked.
  3. If this works, incorporate it into the other commands.
bklockwood commented 8 years ago

Having read Remoting the Implicit Way, I see a few problems I would rather avoid. So I guess I will have to do something a little more involved:

  1. Check whether -Computername evaluates to anything other than localhost
  2. Check for installed PSWU on the RemotePC.
  3. Check that its version matches the local PSWU version
  4. Copy PSWU to appropriate module dir on RemotePC
  5. Import it
  6. Once installed and imported, invoke whatever cmdlet was called for.
bklockwood commented 8 years ago

I have made some progress with an approach that does not require pushing the module to remote machine and installing it there.

Currently I have Get-UpdateList working great remotely (via invoke-command, basically). But I do not have a clean way to pass its results to Install-Updates. I have not checked this code in yet!

bklockwood commented 8 years ago

I've tried this solution. But I need multiple cmdlets from the same module to be work properly on the remote, and to pass objects to one another via the pipeline. And this solution seems not to allow that.

Then I tried this one, which seemed perfect. But I get a ton of 'Access Denied' and I cannot see why - I'm running as local admin on both local and remote PCs.

So now I am looking into ways to simply install (or update) the module over an invoke-command session. Hopefully without setting up a fileshare to pull from.

bklockwood commented 8 years ago

I've discovered a possible bug in PowerShell v5. Invoke-Command does not return output from cmdlets run on v2 systems, when they were invoked from v5 systems. Report

bklockwood commented 8 years ago

Resolved in latest dev-branch commit