Posted On May 27, 2019

Windows 10: Update Script

kimconnect 0 comments
blog.KimConnect.com >> Codes >> Windows 10: Update Script

8/7/2020: there’s an updated version of this script here.

function updateWindows{
# Set PowerShell Gallery as Trusted to bypass prompts
$trustPSGallery=(Get-psrepository -Name 'PSGallery').InstallationPolicy
If($trustPSGallery -ne 'Trusted'){
Install-PackageProvider -Name Nuget -Force
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted -Confirm:$false
}

#Install the PowerShell Windows Update module
$checkModule=Get-Module -ListAvailable -Name PSWindowsUpdate
if(!($checkModule)){Install-Module PSWindowsUpdate -Confirm:$false;}

# Register Windows Update Service if it has not been registered
$MicrosoftUpdateID="7971f918-a847-4430-9279-4a52d1efe18d"
$registered=$MicrosoftUpdateID -in (Get-WUServiceManager).ServiceID
if (!($registered)){
Add-WUServiceManager -ServiceID 7971f918-a847-4430-9279-4a52d1efe18d -Confirm:$false
}

# Perform Updates
set-executionpolicy bypass -force
Get-WindowsUpdate -AcceptAll -MicrosoftUpdate -Install -IgnoreReboot;
"Done.";
}

updateWindows;

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

Basic JavaScript: Constructing Strings with Variables

// Examplevar ourName = "freeCodeCamp";var ourStr = "Hello, our name is " + ourName +…

Install Files within the NewPCSetupFiles Template Directory

net use y: \\FILESERVER01.kimconnect.com\users\template\newPCSetup y: regedit.exe /s disable_uac_win7.reg cd NewPCSetupFiles dotnetfx-winfsc.exe /Q dotNetFx40_Full_x86_x64.exe /quiet /norestartdotnetfx45_full_x86_x64.exe…

PowerShell: Connect to Azure CLI

# Set PSGallery as trusted to bypass promptsSet-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted -WarningAction SilentlyContinue #…