This commit is contained in:
2020-08-14 14:19:37 -04:00
parent d18f8dad97
commit f2b358d8dd
24 changed files with 253 additions and 180 deletions
+12 -17
View File
@@ -1,11 +1,13 @@
param(
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 }
## 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 {
@@ -15,21 +17,14 @@ $Services.Split(",") | ForEach {
$status = (Get-Service -Name $service -ErrorAction SilentlyContinue).Status
## Make sure the service exists
if ($status) {
## Make sure the service isn't currently running
if ($status -ne "Running") {
## Try to restart the service
Write-Host "Restarting ${service}"
try { Restart-Service -Name $service -Force -ErrorAction Stop }
## Write any errors to the host
catch { Write-Host $_ }
If ( $status ) {
} else { Write-Host "${service} is already running" }
## Try to restart the service
Write-Output "Restarting ${service}"
Try { Restart-Service -Name $service -Force -ErrorAction SilentlyContinue }
Catch { Write-Output $_ }
} else { Write-Host "${service} does not exist" }
} Else { Write-Output "${service} does not exist" }
}
}