Posted On July 27, 2022

PowerShell: How to Reset Windows Update Service

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: How to Reset Windows Update Service
# resetWindowsUpdateService
# This is a legacy method of reseting Windows Update
# Since most enterprises are having antiviruses nowadays, I've included an example of how to disable Palo Alto XDR Traps are a required to reset WuApp

$trapsAdminPassword='PASSWORDHERE'
$trapsBin='C:\Program Files\Palo Alto Networks\Traps'

function resetWindowsUpdateService{
	try{
		net stop wuauserv
		net stop cryptSvc
		net stop bits
		net stop msiserver
		mkdir C:\emptyDirectory
		md -Force C:\emptyDirectory
		Remove-Item "C:\emptyDirectory\*" -force -recurse -ErrorAction Continue
		robocopy C:\emptyDirectory C:\Windows\SoftwareDistribution /mir /R:0 /W:0 /NP
		robocopy C:\emptyDirectory C:\Windows\System32\catroot2 /mir /R:0 /W:0 /NP
		net start wuauserv
		net start cryptSvc
		net start bits
		net start msiserver
		return $true
	}catch{
		write-warning $_
	}
}

function stopXdr{
	param(
		$trapsAdminPassword,
		$trapsBin='C:\Program Files\Palo Alto Networks\Traps'
	)
	echo $trapsAdminPassword | & "$trapsBin\cytool.exe" runtime stop
}

function startXdr{
	param(
		$trapsAdminPassword,
		$trapsBin='C:\Program Files\Palo Alto Networks\Traps'
	)
	echo $trapsAdminPassword | & "$trapsBin\cytool.exe" runtime start
}

stopXdr $trapsAdminPassword
resetWindowsUpdateService
startXdr $trapsAdminPassword

Leave a Reply

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

Related Post

PowerShell: How To Bypass Double Hop Problems

# This is a working example of hoping without delegation. Fresh creds can be passed…

PowerShell: Script to Stop, Start, Disable, and Enable Exchange Server

<#This script contains a set of functions to administer Exchange 2010, 2013, 2016, and 3000.…

PowerShell: Set Application CPU Affinity on Remote and Local Computers

# setProcessNameToCpuNumber.ps1$computerName =$env:computername$processname="Chrome";function getProcessors{ param( $computerName=$env:computername ) [int]$processors = 0; $cpuObject = Get-WmiObject -computername $computerName…