I created the script below to scan my list of computer and stop and disable print spooler service. It generates report, showing the service was stopped, but i check a computer on the list and it shows as running. Is something off with the script?
$computers = Get-Content -Path "C:\temp2\ComputerList.txt"
foreach ($computer in $computers) {
if(!(Test-Connection -ComputerName $computer -Count 1 -Quiet))
{
Write-Output "$computer is offline"
continue
}
$service = Get-Service -name Spooler -computername $computer
$ServiceStatus = $service.Status
$ServiceDisplayName = $service.DisplayName
if ($ServiceStatus -eq 'Running') {
write-output "$ServiceDisplayName is $ServiceStatus on $computer and needs to be disabled" | Out-File -FilePath C:\temp2\RunningSpooler.txt -Append
Stop-Service -Name Spooler -Force -PassThru | Out-File -FilePath C:\temp2\RunningSpooler.txt -Append
Set-Service -Name Spooler -StartupType Disabled
}
else {
write-output "Status of $ServiceDisplayName is $ServiceStatus on $computer" | Out-File -FilePath C:\temp2\RunningSpooler.txt -Append
}
}