PoshCode Archive  Artifact [77fb147c29]

Artifact 77fb147c29dc4dbcb43067d60a029e1172418cab4f6997dbc92232dc4c536c72:

  • File StopSQLServices.ps1 — part of check-in [b88d5f9535] at 2018-06-10 13:37:40 on branch trunk — ############################################################################################# (user: unknown size: 2120)

# encoding: ascii
# api: powershell
# title: StopSQLServices.ps1
# description: #############################################################################################
# version: 0.1
# type: script
# license: CC0
# x-poshcode-id: 4165
# x-archived: 2017-03-16T01:19:45
#
# #
# NAME: StopSQLServices.ps1
# AUTHOR: Rob Sewell http://newsqldbawiththebeard.wordpress.com @fade2blackuk
# DATE:15/05/2013
# #
# COMMENTS: This script will stop all SQL Services on a server
# ————————————————————————————————————
#
#############################################################################################
#
# NAME: StopSQLServices.ps1
# AUTHOR: Rob Sewell http://newsqldbawiththebeard.wordpress.com @fade2blackuk
# DATE:15/05/2013
#
# COMMENTS: This script will stop all SQL Services on a server
# ------------------------------------------------------------------------

$Server= Read-Host "Please Enter the Server - This WILL stop all SQL services"

Write-Host "###########  Services on $Server BEFORE  ##############" -ForegroundColor Green -BackgroundColor DarkYellow
get-service -ComputerName $server|Where-Object { $_.Name -like '*SQL*' }
Write-Host "###########  Services on $Server BEFORE  ##############" -ForegroundColor Green -BackgroundColor DarkYellow
$Services = Get-Service -ComputerName $server|Where-Object { $_.Name -like '*SQL*' -and $_.Status -eq 'Running' -and $_.Name -ne 'SQLSERverAGENT'}

foreach($Service in $Services)
{
if($service.Status -eq 'Running')
{
$ServiceName = $Service.displayname
(get-service -ComputerName $Server  -Name $ServiceName).Stop()
 while((Get-Service -ComputerName $server -Name $ServiceName).status -ne'Stopped')
 {<#do nothing#>}
 }
 }
Write-Host "###########  Services on $Server After  ##############" -ForegroundColor Green -BackgroundColor DarkYellow
get-service -ComputerName $server|Where-Object { $_.Name -like '*SQL*' }
Write-Host "###########  Services on $Server After  ##############" -ForegroundColor Green -BackgroundColor DarkYellow