Friday, December 11, 2015

Powershell script to execute PSExec to install MSU updates.

#Variable 
$TLS_Update_64bit = "C:\tmp\Windows6.1-KB2574819-v2-x64_DTLS.msu"

$RDP8_Update_64bit = "C:\tmp\Windows6.1-KB2592687-x64_RDP8.msu"

ForEach($computer in $(Get-Content "C:\tmp\computers.txt")){


#Check Architecture 32 bit or 64 bit
If($(Get-WmiObject Win32_OperatingSystem -ComputerName $computer).OSArchitecture -eq "64-bit"){

#Copy MSU files to Workstations   
Copy-Item $TLS_Update_64bit,$RDP8_Update_64bit "\\$computer\c$\temp\" -Force

& C:\tmp\PsExec.exe -s -d \\$computer powershell.exe "enable-psremoting -force"

#Use PsExec to install MSU file   
& C:\tmp\PsExec.exe -s -high \\$computer wusa c:\temp\Windows6.1-KB2574819-v2-x64_DTLS.msu /passive /quiet /norestart

& C:\tmp\PsExec.exe -s -high \\$computer wusa c:\temp\Windows6.1-KB2592687-x64_RDP8.msu /passive /quiet /norestart

#Check for results of the Install   
if ($LastExitCode -eq 3010,2359302) {

$ConfirmReboot = $False

} else {

$ConfirmReboot = $True



}
#Check to verify Updates are installed       
Get-Hotfix -id KB2574819 -computername $computer

Get-Hotfix -id KB2592687 -computername $computer

#Remove MSU files from host       
Remove-Item "\\$computer\c$\Temp\Windows6.1-KB2574819-v2-x64_DTLS.msu"

Remove-Item "\\$computer\c$\Temp\Windows6.1-KB2592687-x64_RDP8.msu"

Write-Host "Files $TLS_Update_64bit and $RDP8_Update_64bit do not exist on the target Computer"

Write-Host "Restarting $computer..."

#Initiate a host reboot if needed       
Restart-Computer -ComputerName $computer -Force -Confirm:$ConfirmReboot



}

}

No comments:

Post a Comment