script to stop/disable spooler service on all servers not required in regards to Print Spooler Vulnerability

 

script to stop/disable spooler service on all servers not required

regarding the Print Nightmare vulnerability,  I have deal with all 226 sql servers and 12 oracle servers on windows, so resue one of my ps script to stop /disable spooler service on all servers. this also helps to disable spooler on some of other 10000+ windows machines we have. 


Windows Print Spooler Remote Code Execution Vulnerability

 https://msrc.microsoft.com/update-guide/vulnerability/CVE-2021-34527 

step1, create a list of servers to change in text file with one servername in a line, saved it toc:\sql\serverlist0.txt


step 2. copy below script to power script ISE

step 3. run it, see screenshot

$service = "Spooler"



$text=Get-Content C:\sql\serverlist0.txt
$TotalComputers=$text.Length
write-host "the total number of computers is $TotalComputers"
For ($i=0; $i -lt $text.Length; $i++) {
$Computer= $text[$i]
Write-Host "Working on $Computer"
if(!(Test-Connection -ComputerName $Computer -Count 1 -quiet)) {
Write-Warning "$computer : Offline"
Continue
}
try {
$ServiceObject = Get-WMIObject -Class Win32_Service -ComputerName $Computer -Filter "Name='$service'" -EA Stop
if(!$ServiceObject) {
Write-Warning "$Computer : No service found with the name $service"
Continue
}
if($ServiceObject.StartMode -eq "Disabled") {
Write-Warning "$Computer : Service with the name $service already in disabled state"
# Continue
}
Set-Service -ComputerName $Computer -Name $service -EA Stop -StartMode Disabled
Write-Host "$Computer : Successfully disabled the service $service. Trying to stop it"
if($ServiceObject.state -ne "Running") {
Write-Warning "$Computer : $service already in stopped state"
Continue
}
$retval = $ServiceObject.StopService()
if($retval.ReturnValue -ne 0) {
Write-Warning "$Computer : Failed to stop service. Return value is $($retval.ReturnValue)"
Continue
}
Write-Host "$Computer : Stopped service successfully"
} catch {
Write-Warning "$computer : Failed to query $service. Details : $_"
Continue
}


#sample serverlist0.txt
sampleServerName1
sampleServerName2
sampleServerName3



Comments

Popular posts from this blog

Sysaux tablespace is too big

patching Oracle Database 12.2.0.1 Release Update & Release Update Revision January 2021 Critical Issues (Doc ID 2725763.1)