Files
management-scripts/Remediation-RestartServices.ps1
T
2020-08-14 14:19:37 -04:00

30 lines
778 B
PowerShell

Function Remediation-RestartServices
{
param(
[Int32]$Wait=0,
[Parameter(Mandatory=$true)]
[string]$Services
)
## Wait for the specIfied amount of time before proceeding
If ( $Wait -gt 0 ) { Start-Sleep -Seconds $Wait }
##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
If ( $status ) {
## Try to restart the service
Write-Output "Restarting ${service}"
Try { Restart-Service -Name $service -Force -ErrorAction SilentlyContinue }
Catch { Write-Output $_ }
} Else { Write-Output "${service} does not exist" }
}
}