Quantcast
Channel: PowerShell.com – PowerShell Scripts, Tips, Forums, and Resources
Viewing all articles
Browse latest Browse all 6937

Install Powershell 4 Remotely

$
0
0

Hi,

Trying to upgrade PoSh to v4 on several machines and having no luck.  Worked for a few with Chocolatey, but then I started getting Exit Code 5.  

So I went down a new path and found a script elsewhere that I bastardized:

 

$computers = Get-ADComputer -searchbase "OU=CityA,DC=Contoso,DC=local" -Filter {OperatingSystem -NotLike "*server*"} | select-object -expandproperty name

$cred = Get-Credential cnp\administrator

ForEach($Computer in $Computers){

 Copy-Item "D:\ClientApps\Windows6.1-KB2819745-x64-MultiPkg.msu" \\$computer\c$ -Force

}

   $cmd={

        Start-Process 'wusa.exe' -ArgumentList "C:\Windows6.1-KB2819745-x64-MultiPkg.msu /extract:C:\MSU\" -Wait -PassThru

        Start-Process dism.exe -ArgumentList "/online /add-package /PackagePath:C:\MSU\Windows6.1-KB2809215-x64.cab /NoRestart" -Wait -PassThru

        Start-Process dism.exe -ArgumentList "/online /add-package /PackagePath:C:\MSU\Windows6.1-KB2872035-x64.cab /NoRestart" -Wait -PassThru

        Start-Process dism.exe -ArgumentList "/online /add-package /PackagePath:C:\MSU\Windows6.1-KB2872047-x64.cab /NoRestart" -Wait -PassThru

        Start-Process dism.exe -ArgumentList "/online /add-package /PackagePath:C:\MSU\Windows6.1-KB2819745-x64.cab /NoRestart" -Wait -PassThru

        Remove-Item C:\MSU -Recurse -Force

        Restart-Computer -Force

    }

Invoke-Command -ComputerName $computers -ScriptBlock {$cmd}

Running that, even -AsJob seems to go nowhere though - sometimes it does the file copy at least.  If I Enter-PSSession into a few of the computers and run commands one by one, I can sometimes get it to create the MSU folder or start the processes, but in the end nothing upgraded.

What am I missing?


Viewing all articles
Browse latest Browse all 6937

Trending Articles