moved Delete-File function to Tools.ps1

removed global variable
This commit is contained in:
2021-10-08 05:40:58 -04:00
parent 433e7dcc83
commit 087516fde3
+3 -20
View File
@@ -1,25 +1,8 @@
$Global:_FixAteraAgentRestartAgent = $false
Function Delete-File ([Parameter(ValueFromPipeline=$true)][string]$path) {
If ( Test-Path $path ) {
If ( !((Get-Item $path) -is [System.IO.DirectoryInfo]) ) {
$Global:_FixAteraAgentRestartAgent = $true
Try {
LogMsg "Delete ""${path}"""
Remove-Item $path -Force
}
Catch { LogErr $_.Exception.Message }
}
}
}
## Remove cached files related to thresholds and alerts
"${Env:PROGRAMFILES}\ATERA Networks\AteraAgent\Packages\AgentPackageMonitoring\AlertsCache.cch",
"${Env:PROGRAMFILES}\ATERA Networks\AteraAgent\Packages\AgentPackageMonitoring\AlertsSentCache.cch",
"${Env:PROGRAMFILES}\ATERA Networks\AteraAgent\Packages\AgentPackageMonitoring\config.json" | Delete-File
If ($Global:_FixAteraAgentRestartAgent) {
LogMsg "Restarting Atera Agent service"
Try { Control-Service -Restart -Name "AteraAgent" -Force }
Catch { LogErr $_.Exception.Message }
}
LogMsg "Restarting Atera Agent service"
Try { Control-Service -Restart -Name "AteraAgent" -Force }
Catch { LogErr $_.Exception.Message }