-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutomationPlannedServiceRestarts.ps1
40 lines (26 loc) · 1.2 KB
/
AutomationPlannedServiceRestarts.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
<# Automation of planned service restarts#>
$BASE_DIR = (Resolve-Path .\).Path
$ddmmyyyy = (Get-Date).ToString('dd-mm-yyyy');
$LOG_FILE = $BASE_DIR + "\Daily_Service_Restart_$ddmmyyyy`.log"
Start-Transcript -Path "$LOG_FILE"
$config_file = $BASE_DIR + "\service.ini"
$arr_servers = Get-Content $config_file
$services = "pla", "Spooler","WpnService"
Write-Output "${get-data} :INFO Starting the script execution"
Invoke-Command -ComputerName $arr_servers -ScriptBlock {
$sleeptime = 30;
Write-Output "$(Get-Date) :INFO Fetching the initial status of services"
Get-Service -Name $Using:services | select name, status, PSComputerName
Write-Output "$(Get-Date) :INFO Stopping Services"
Stop-Service -Name $Using:services
sleep($sleeptime)
Write-Output "$(Get-Date) :INFO Checking the status to see if the services are stopped"
Get-Service -Name $Using:services | select name, status, PSComputerName
sleep($sleeptime)
Write-Output "$(Get-Date) :INFO starting the services"
Start-Service -Name $Using:services
sleep($sleeptime)
Write-Output "$(Get-Date) :INFO FINAL Status"
Get-Service -Name $Using:services | select name, status, PSComputerName
}
Stop-Transcript