Stop and Disable a Service - PowerShell
This script/function will list all the services using Grid-View and allow you to select one to stop and disable it.
function DisableStopServ($tService){
#The object will be loaded from the variable passed to it.
#Check to see if the target service is running and try to stop it.
if(($tService).Status -eq "Running"){
Write-Host "The" ($tService).DisplayName "service is currently" ($tService).Status
Write-Host "Attempting to stop the service"
#Stop the target service
Stop-Service $tService -Force
Write-Host "The" ($tService).DisplayName "service is currently" $tService.Status
}
else{
Write-Host "The" ($tService).DisplayName "service is already" ($tService).Status
}
#Check to see if the target service startup type is disabled and set it do disabled if it is not already.
if(($tService).StartType -eq "Disabled"){
Write-Host "The" ($tService).DisplayName "service startup type is already" ($tService).StartType
}
else{
Write-Host "The" ($tService).DisplayName "service startup type is currently" ($tService).StartType
Write-Host "Changing the Start Type to Disabled"
#Change the startup type to disabled
Set-Service -InputObject $tService -StartupType Disabled
Write-Host "The" ($tService).DisplayName "service startup type is currently" (Get-Service -Name $tService.ServiceName).StartType
}
}
DisableStopServ(Get-Service | Out-GridView -PassThru)