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" } } }