53 lines
1.7 KiB
PowerShell
53 lines
1.7 KiB
PowerShell
Function Remediation-RestartService
|
|
{
|
|
param([Parameter(Mandatory=$true,ValueFromPipeline=$true)][string[]]$Name)
|
|
ForEach ( $service in $Name )
|
|
{
|
|
Remediation-StopService -Name $service
|
|
}
|
|
}
|
|
|
|
Function Remediation-StopService
|
|
{
|
|
param([Parameter(Mandatory=$true,ValueFromPipeline=$true)][string[]]$Name)
|
|
ForEach ( $service in $Name )
|
|
{
|
|
$status = (Get-Service -Name $service -ErrorAction SilentlyContinue).Status
|
|
If ( $status -ne "Stopped" )
|
|
{
|
|
LogMsg " Stopping '${service}'"
|
|
Try { Stop-Service -Name $service -Force -ErrorAction SilentlyContinue }
|
|
Catch { LogErr $_.Exception.Message }
|
|
}
|
|
Else { LogMsg " '${service}' service is already stopped" }
|
|
}
|
|
}
|
|
|
|
Function Remediation-StartService
|
|
{
|
|
param([Parameter(Mandatory=$true,ValueFromPipeline=$true)][string[]]$Name)
|
|
ForEach ( $service in $Name )
|
|
{
|
|
$service = "bogus"
|
|
$status = (Get-Service -Name $service -ErrorAction SilentlyContinue).Status
|
|
If ( !($status) )
|
|
{
|
|
Write-Host "Cannot find the service '${service}', attempting to match a service display name instead"
|
|
$status = Get-Service | Where { $_.DisplayName -match $service }
|
|
Write-Host $status
|
|
}
|
|
Else { Write-Host "Status is: ${status}" }
|
|
If ( $status -eq "StartPending" )
|
|
{ LogMsg " '${service}' was previously started, and is still starting up" }
|
|
ElseIf ( $status -ne "Running" )
|
|
{
|
|
LogMsg " Starting '${service}'"
|
|
Try { Start-Service -Name $service -Force -ErrorAction SilentlyContinue }
|
|
Catch { LogErr $_.Exception.Message }
|
|
}
|
|
Else { LogMsg " '${service}' service is already running" }
|
|
}
|
|
}
|
|
|
|
[string[]]$list = "apple", "orange", "banana", "pineapple"
|
|
Write-Host "Here are the list items: ${list}" |