-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stop-AOS.ps1
41 lines (34 loc) · 1010 Bytes
/
Stop-AOS.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
33
34
35
36
37
38
39
40
#Stop-AOS
Param(
[string[]]$aosServerNames = $env:COMPUTERNAME,
$aosServiceName = 'AOS60$01'
)
try
{
$servicesList = New-Object System.Collections.ArrayList
foreach ($AOSServer in $aosServerNames)
{
$service = Get-Service -ComputerName $AOSServer $aosServiceName
if ($service.Status -eq "Running" -and $service.CanStop -eq $True)
{
$servicesList.Add($service) | Out-Null
Write-Output "Stopping AOS in $AOSServer"
$service.Stop()
}
else
{
Write-Output "Could not stop AOS in $AOSServer"
}
}
foreach ($service in $servicesList)
{
Write-Output "Waiting for server $($service.MachineName) to stop"
$service.WaitForStatus("stopped")
Write-Output "AOS in' $($service.MachineName) is stopped"
}
}
catch
{
Write-Output "Error stoping AOS"
break
}