Remote Deploy Update Powershell Version

This topic contains 7 replies, has 4 voices, and was last updated by  Laurent Maene 1 week, 6 days ago.

  • Author
    Posts
  • #80846

    Laurent Maene
    Participant

    Hello the PS Communnity,

    I'm trying to remote deploy the 'latest' version of Powershell but I have some difficulties.

    Here is 'my' approach but it doesn't seem to work. Trying on "Win7x64SP1 Enterprise" machine.

    1st approach

    $Cred = New-Object System.Management.Automation.PSCredential ($username, $Password)
    Enter-PSSession -ComputerName (Read-Host -Prompt "enter computer name") -Credential $cred
    Start-Process -FilePath wusa.exe -ArgumentList '"\\server\path\UpdateForThePowershellVersion.msu" /quiet /norestart' -wait
    exit

    2nd approach

    $Cred = New-Object System.Management.Automation.PSCredential ($username, $Password)
    Invoke-Command -ComputerName (Read-Host -Prompt "enter computer name") -ScriptBlock {
    Start-Process -FilePath wusa.exe -ArgumentList '"\\server\path\UpdateForThePowershellVersion.msu" /quiet /norestart' -wait
    } -Credential $cred

    Nothing happens ...
    What's wrong? Is there a better working manner to update powershell on remote machine?

    Thanks in advance for a little help here ...
    Kind regards,
    Laurent Maene.

  • #80854

    Will Prather
    Participant

    Not sure with wusa.exe specifically, but in order to handle Windows updates remotely, we created a scheduled task to run as system on the target machine. When the task runs it is a local process and seems to work. As I understand it, the update process in general does not accept remote commands.

    You could likely take either of your scripts and use that as the local script with a couple changes, like mor using invoke-command. The script you would run remotely would simply create a scheduled task.

    This might help, https://blogs.technet.microsoft.com/heyscriptingguy/2015/01/13/use-powershell-to-create-scheduled-tasks/.

    If not, you might google using schtask.exe in powershell to create your script.

  • #80896

    Naw Awn
    Participant

    Hello Maene

    I had the same situation like yours. This was what I ended up doing. It's not very pretty but it worked.

    1. Extract the msu file from command prompt, grab the .cab file and save it to a network share.
      C:\expand -F:* KB3033929.msu C:\temp
    2. Use the PowerShell script below. I assume you already set up your environment for WinRM (This is done via the group policies)
    
    
    Param(
        [Parameter(Mandatory=$true)]
        [String]$ComputerName
    )
    
    Copy-Item "\\Server\Share\software\MSU\Windows6.1-KB3033929-x64.cab" "\\$ComputerName\C$\temp\"
    
    Invoke-Command -ComputerName $ComputerName {
        dism.exe /online /add-package /PackagePath:C:\Temp\Windows6.1-KB3033929-x64.cab
        #Remove-Item c:\temp\Windows6.1-KB3033929-x64.cab
    }
    

    You can run this in the background as a job. Well, let me know how it goes.

    My preferred solution to this was to use DSC. Look for xWindowsUpdate dsc module in PowerShell gallery.
    The code will be like this but I haven't tried it myself yet.

    Configuration UpdateWindowsWithPath 
    {        
        Node 'ClientComputer' 
        {  
            xHotfix HotfixInstall 
            { 
                Ensure = "Present" 
                Path = "c:/temp/Windows8.1-KB2908279-v2-x86.msu" 
                Id = "KB2908279" 
            }  
        }  
    } 
    #UpdateWindowsWithPath
    #Start-DscConfiguration -Path c:\temp\ClientComputer.mof -ComputerName PC1
    
  • #80909

    Rick
    Participant

    I suggest looking at chocolatey. It's a package manager for Windows and it rocks! Windows 10 has a package manager called oneget which also allows you to pull chocolatey packages. Once you get the chocolatey module installed it's super easy to install/uninstall/update apps, etc by just running choco powershell commands either locally or remotely.

    Powershell WMF 5.1 Deployment Issues
    https://cloudywindows.io/post/easing-powershell-wmf-5-1-deployment-challenges-using-the-chocolatey-package/

    Chocolately Install
    https://chocolatey.org/
    Install:

    Set-ExecutionPolicy Bypass; iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

    Chocolatey Powershell 5.1 Install (:
    https://chocolatey.org/packages/PowerShell
    Upgrade Powershell:

    choco upgrade powershell
  • #80914

    Naw Awn
    Participant

    This was what I did when I had to get it working awhile back

    
    Param(
        [Parameter(Mandatory=$true)]
        [String]$ComputerName
    )
    Copy-Item "\\Server\Share\software\MSU\Windows6.1-KB3033929-x64.cab" "\\$ComputerName\C$\temp\"
    
    Invoke-Command -ComputerName $ComputerName {
        dism.exe /online /add-package /PackagePath:C:\Temp\Windows6.1-KB3033929-x64.cab
        #Remove-Item c:\temp\Windows6.1-KB3033929-x64.cab
    }
    
  • #80917

    Naw Awn
    Participant

    The help content doesn't show up for some reason.

  • #80920

    Naw Awn
    Participant

    You have to extract the msu file first from command prompt to get the .cab file.
    If I have to do it again I would use DSC this time around.
    have a look at xWindowsUpdate powershell gallery
    https://gallery.technet.microsoft.com/scriptcenter/xWindowsUpdate-Module-with-5af00a7f
    https://github.com/PowerShell/xWindowsUpdate

    Configuration UpdateWindowsWithPath 
    {        
        Node 'ClientPC' 
        {  
            xHotfix HotfixInstall 
            { 
                Ensure = "Present" 
                Path = "c:/temp/Windows8.1-KB2908279-v2-x86.msu" 
                Id = "KB2908279" 
            }  
        }  
    }
    #UpdateWindowsWithPath 
    #Start-DscConfiguration -Path .\ClientPC.mof -ComputerName PC1
    

    Hope this helps.

    • #81130

      Laurent Maene
      Participant

      Hello,

      Thanks Will Prather, Naw Awn and Rick. You put me on the right way.

      So schedule task and DISM did the trick!

      Start-Process -FilePath 'dism.exe' -ArgumentList "/online /add-package /PackagePath:C:\dbsoudo\powershell\Windows6.1-KB2809215-x64.cab /quiet /norestart" -Wait -WindowStyle Hidden

      For Chocolately, I didn't have the time to check what the initial script does to the machine.

      DSC is definitely the best option here.
      I will check how to implement it.
      I will review the MVA video content about powershell DSC (again).

      BR
      Laurent.

You must be logged in to reply to this topic.