Here is my example below. Using powershell. Make sure on the first step you make a folder LNSWP_log to store the logs. (See step 1)
Copy and paste the code below after the broken line into a ps1 file. Name it whatever you like. I named it CheckforUpdates (brilliant right 😀)
Step 1 " mkdir C:\LNSWP_log # I make a folder where are store all Lansweeper logs for different deploys
Step 2 Start /B powershell -ExecutionPolicy RemoteSigned -File [From your package Share] CheckforUpdates.ps1 -Force
-------------------------------------------------------------------------------
"Start Update: $(Get-Date)" > "C:\LNSWP_Log\Windows_Update.log"
# Check and install NuGet package provider
if (-not (Get-PackageProvider -Name NuGet)) {
"Installing Package NuGet" >> "C:\LNSWP_Log\Windows_Update.log"
Install-PackageProvider -Name NuGet -MinimumVersion '2.8.5.201' -Force >> "C:\LNSWP_Log\Windows_Update.log"
} else {
"Package NuGet already Installed" >> "C:\LNSWP_Log\Windows_Update.log"
}
# Check and install PSWindowsUpdate module
if (-not (Get-Module -ListAvailable -Name PSWindowsUpdate)) {
"Installing Windows Update Module" >> "C:\LNSWP_Log\Windows_Update.log"
Install-Module -Name PSWindowsUpdate -Confirm:$false -Force >> "C:\LNSWP_Log\Windows_Update.log"
} else {
"Windows Update Module already Installed" >> "C:\LNSWP_Log\Windows_Update.log"
}
# Perform Windows Update
Get-WindowsUpdate -IgnoreUserInput -MicrosoftUpdate -ForceDownload -Install -AcceptAll `
-AutoSelectOnWebSites:$true -IgnoreReboot -Confirm:$false >> "C:\LNSWP_Log\Windows_Update.log"
Get-WUInstall -AcceptAll -IgnoreReboot -Install >> "C:\LNSWP_Log\Windows_Update.log"
" " >> "C:\LNSWP_Log\Windows_Update.log"
" " >> "C:\LNSWP_Log\Windows_Update.log"
" Update History" >> "C:\LNSWP_Log\Windows_Update.log"
"----------------" >> "C:\LNSWP_Log\Windows_Update.log"
Get-WUHistory >> "C:\LNSWP_Log\Windows_Update.log"
# Notify user and schedule reboot
cmd.exe /c msg * "Latest Updates have been applied; Please reboot your Computer"
Invoke-Command -ScriptBlock { shutdown /r /t 3600 /d P:2:3 }
Invoke-Command -ScriptBlock { msg * "Latest Updates have been applied; Please reboot your Computer" }
"End Update: $(Get-Date)" >> "C:\LNSWP_Log\Windows_Update.log"