-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisableUnneededServices.ps1
More file actions
57 lines (51 loc) · 1.5 KB
/
DisableUnneededServices.ps1
File metadata and controls
57 lines (51 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#Disable unneeded services in Windows 2008/2003
#Brian Lalancette, 2009
$QueryOS = Gwmi Win32_OperatingSystem -Comp localhost
$QueryOS = $QueryOS.Caption
If ($QueryOS.contains("2008") -or $QueryOS.contains("Vista"))
{
$OS = "Win2008"
$ServicesToSetManual = "Spooler","AudioSrv"
$ServicesToDisable = "WerSvc"
}
If ($QueryOS.contains("2003"))
{
$OS = "Win2003"
$ServicesToSetManual = "Spooler","WZCSVC","AudioSrv","Helpsvc"
$ServicesToDisable = "ERSvc","MpsSvc"
}
ForEach ($SvcName in $ServicesToSetManual)
{
$Svc = get-wmiobject win32_service | where-object {$_.Name -eq $SvcName}
$SvcStartMode = $Svc.StartMode
$SvcState = $Svc.State
If (($SvcState -eq "Running") -and ($SvcStartMode -eq "Auto"))
{
& net stop $SvcName
Set-Service -name $SvcName -startupType Manual
Write-Host "- Service $SvcName is now set to Manual start"
}
Else
{
Write-Host "- $SvcName is already stopped and set to Manual start, no action required."
}
Write-Host "-"
}
ForEach ($SvcName in $ServicesToDisable)
{
$Svc = get-wmiobject win32_service | where-object {$_.Name -eq $SvcName}
$SvcStartMode = $Svc.StartMode
$SvcState = $Svc.State
If (($SvcState -eq "Running") -and (($SvcStartMode -eq "Auto") -or ($SvcStartMode -eq "Manual")))
{
& net stop $SvcName
Set-Service -name $SvcName -startupType Disabled
Write-Host "- Service $SvcName is now stopped and disabled."
}
Else
{
Write-Host "- $SvcName is already stopped and disabled, no action required."
}
Write-Host "-"
}
Write-Host "- Finished disabling services."