Files
management-scripts/Remediation-RestartServices.ps1
T

30 lines
778 B
PowerShell
Raw Normal View History

2020-08-14 14:19:37 -04:00
Function Remediation-RestartServices
{
param(
2019-11-11 19:22:39 -05:00
[Int32]$Wait=0,
[Parameter(Mandatory=$true)]
[string]$Services
)
2020-08-14 14:19:37 -04:00
## Wait for the specIfied amount of time before proceeding
If ( $Wait -gt 0 ) { Start-Sleep -Seconds $Wait }
2019-11-11 19:22:39 -05:00
##Split the list of services so we can process each one
$Services.Split(",") | ForEach {
## Get the service's status
$service = $_
$status = (Get-Service -Name $service -ErrorAction SilentlyContinue).Status
## Make sure the service exists
2020-08-14 14:19:37 -04:00
If ( $status ) {
2019-11-11 19:22:39 -05:00
2020-08-14 14:19:37 -04:00
## Try to restart the service
Write-Output "Restarting ${service}"
Try { Restart-Service -Name $service -Force -ErrorAction SilentlyContinue }
Catch { Write-Output $_ }
2019-11-11 19:22:39 -05:00
2020-08-14 14:19:37 -04:00
} Else { Write-Output "${service} does not exist" }
2019-11-11 19:22:39 -05:00
}
2020-08-14 14:19:37 -04:00
}