-
Notifications
You must be signed in to change notification settings - Fork 3
/
start-services.ps1
32 lines (27 loc) · 1.13 KB
/
start-services.ps1
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
# Make sure to use the elevated permissions
if (!([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Start-Process pwsh.exe "-NoProfile -ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs; exit
}
# List of services to be started
$serviceNames = ('MSSQLSERVER')
Write-Host '>> START SERVICES <<' -BackgroundColor White -ForegroundColor DarkGreen
Write-Host ''
foreach ($serviceName in $serviceNames) {
$service = Get-Service -Name $serviceName
Write-Host $service.DisplayName -BackgroundColor DarkGray -ForegroundColor White
while ($service -ne 'Running') {
Write-Host 'Status: ' -NoNewline
if ($service.Status -eq 'Running') {
Write-Host $service.Status -BackgroundColor Black -ForegroundColor Green
Write-Host ''
break;
}
else {
Start-Service $ServiceName
Write-Host 'Starting...' -ForegroundColor Gray
$service.Refresh()
}
}
}
#Holds the window for a while before it closes
Start-Sleep -seconds 10