major logging overhaul, plus other fixes

This commit is contained in:
2020-10-22 14:01:35 -04:00
parent 77cf4d6276
commit 978373ebe2
27 changed files with 430 additions and 611 deletions
+51 -28
View File
@@ -1,30 +1,53 @@
Function Remediation-RestartServices
Function Remediation-RestartService
{
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" }
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}"