Quantcast
Channel: PowerShell.org » All Posts
Viewing all articles
Browse latest Browse all 13067

Reply To: Installing .MSU Via Powershell & PSexec

$
0
0

Gosh I must have been sleeping when I wrote my last post… I see what I did wrong, essentially I did not set the computername parameter for Wet-WMIObject therefore the OS architecture would always come up as the architecture of the machine you’re running the script on and not the remote machines. Here I’ve updated the script for you to try again:


<code>
$HotFix_32bit = "F:\WindowsManagementFramework4.0\Update\Windows6.1-KB2819745-x86-MultiPkg.msu"
$HotFix_64bit = "F:\WindowsManagementFramework4.0\Update\Windows6.1-KB2819745-x64-MultiPkg.msu"

ForEach($computer in $(Get-Content "F:\WindowsManagementFramework4.0\Computer Lists\test list.txt")){

If($(Get-WmiObject Win32_OperatingSystem -ComputerName $computer).OSArchitecture -eq "64-bit"){

    Copy-Item $HotFix_64bit "\\$computer\c$" -Force

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

        Start-Process dism.exe -ArgumentList '/online /add-package /PackagePath:C:\MSU\Windows6.1-KB2809215-x64.cab /NoRestart' -Wait
        Start-Process dism.exe -ArgumentList '/online /add-package /PackagePath:C:\MSU\Windows6.1-KB2872035-x64.cab /NoRestart' -Wait
        Start-Process dism.exe -ArgumentList '/online /add-package /PackagePath:C:\MSU\Windows6.1-KB2872047-x64.cab /NoRestart' -Wait
        Start-Process dism.exe -ArgumentList '/online /add-package /PackagePath:C:\MSU\Windows6.1-KB2819745-x64.cab /NoRestart' -Wait

        Remove-Item C:\MSU -Recurse -Force

        Restart-Computer -Force
    }

}ElseIf($(Get-WmiObject Win32_OperatingSystem -ComputerName $computer).OSArchitecture -eq "32-bit"){

    Copy-Item $HotFix_32bit "\\$computer\c$" -Force

    $cmd={
        Start-Process wusa.exe -ArgumentList '"C:\Windows6.1-KB2819745-x86-MultiPkg.msu" /extract:C:\MSU\' -Wait

        Start-Process dism.exe -ArgumentList '/online /add-package /PackagePath:C:\MSU\Windows6.1-KB2872035-x86.cab /NoRestart' -Wait
        Start-Process dism.exe -ArgumentList '/online /add-package /PackagePath:C:\MSU\Windows6.1-KB2872047-x86.cab /NoRestart' -Wait
        Start-Process dism.exe -ArgumentList '/online /add-package /PackagePath:C:\MSU\Windows6.1-KB2819745-x86.cab /NoRestart' -Wait

        Remove-Item C:\MSU -Recurse -Force

        Restart-Computer -Force
    }
}

Invoke-Command -ComputerName $computer -ScriptBlock $cmd

}

Sorry about that... Go ahead and try again.

Have you thought about my question? What version of Windows is your 32-bit server running?

In response to your last post, I don't see how the $connection variable would have anything in it as there is no output from out-file. Try replacing that line with this:


Test-Connection -ComputerName $Computer -Quiet -Count 1 | Tee-Object -Variable connection | Out-File -FilePath F:\Script-Log.txt -Append

note that tee-object requires at least Powershell v3.

Also since you're using out-file, out-file overwrites a previously existing file, hence why you are only seeing one entry in the log. Either add -Append to the out-file, or use add-content instead.

You could also put the test-connection cmdlet into the if statement.


if(test-connection -computername $computer -count 1 -quiet){
   "$computer is online"
   add-content -path F:\Script-Log.txt -value "$computer is online"
}Else{
   "$computer is offline"
   add-content -path F:\Script-Log.txt -value "$computer is offline"
}

Viewing all articles
Browse latest Browse all 13067

Trending Articles