Created
November 2, 2015 14:06
-
-
Save ctigeek/7cce331f62c7c16137e3 to your computer and use it in GitHub Desktop.
Install all available windows updates on a computer. This requires PsExec to be installed locally (not on the remote computer.)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Install-WindowsUpdates($computerName) { | |
| $command = { | |
| if (! (Test-Path c:\updates )) { New-Item c:\updates -ItemType Directory } | |
| if (Test-Path c:\updates\installUpdates.ps1 ) { Remove-Item c:\updates\installUpdates.ps1 -Force -Confirm:$false } | |
| "Get-WUInstall -AcceptAll -AutoReboot -Verbose " | Out-File c:\updates\installUpdates.ps1 | |
| } | |
| Invoke-Command -ComputerName $computerName -ScriptBlock $command | |
| ##WSUS doesn't like remote execution... so we have to jump through several hoops to make it think it's executing locally.... | |
| if (Test-Path \\$computerName\c$\updates\prepareForReboot.ps1 ) { | |
| ## Prepare for reboot is an optional script you can install on the remote server to gracefully shutdown things before reboot. | |
| Write-Host "Running prepareForReboot.ps1" | |
| .\PsExec.exe \\$($computerName) -s powershell -File c:\updates\prepareForReboot.ps1 | |
| } | |
| .\PsExec.exe \\$($computerName) -s powershell -File c:\updates\installUpdates.ps1 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment