Tools.ps1: move all processes into functions and explicitly declare global variables
Test-InternetBandwidth.ps1: output to console instead of file Uninstall-NCentralComponents.ps1: minor updates
This commit is contained in:
@@ -31,13 +31,14 @@ Catch { LogErr $_.Exception.Message }
|
|||||||
## Run the SpeedTest CLI app
|
## Run the SpeedTest CLI app
|
||||||
$SPEEDTEST = "${WORKINGDIR}\speedtest.exe"
|
$SPEEDTEST = "${WORKINGDIR}\speedtest.exe"
|
||||||
If ( Test-Path $SPEEDTEST ) {
|
If ( Test-Path $SPEEDTEST ) {
|
||||||
Try { Start-Process $SPEEDTEST -ArgumentList "--progress=no --selection-details --output-header --format=csv" -PassThru -Wait -RedirectStandardOutput $OUTPUT }
|
#Try { Start-Process $SPEEDTEST -ArgumentList "--progress=no --selection-details --output-header --format=csv" -PassThru -Wait -RedirectStandardOutput $OUTPUT }
|
||||||
|
Try {
|
||||||
|
$RESULTS = (cmd.exe /c "${SPEEDTEST} --progress=no")
|
||||||
|
LogMsg $RESULTS
|
||||||
|
}
|
||||||
Catch { LogErr $_.Exception.Message }
|
Catch { LogErr $_.Exception.Message }
|
||||||
} Else { LogMsg "The file does not exist at the expected path: ""${SPEEDTEST}""" }
|
} Else { LogMsg "The file does not exist at the expected path: ""${SPEEDTEST}""" }
|
||||||
|
|
||||||
## Process the results
|
|
||||||
|
|
||||||
|
|
||||||
## Cleanup files and directories created by this script
|
## Cleanup files and directories created by this script
|
||||||
If ( Test-Path $ZIPFILE ) {
|
If ( Test-Path $ZIPFILE ) {
|
||||||
LogMsg "Deleting downloaded zip file: ""$ZIPFILE"""
|
LogMsg "Deleting downloaded zip file: ""$ZIPFILE"""
|
||||||
|
|||||||
@@ -1,30 +1,54 @@
|
|||||||
## Define the MSP name
|
## Define the MSP name
|
||||||
$MSPName = "Emberkom"
|
[string]$Global:MSPName = "Emberkom"
|
||||||
|
|
||||||
|
## This section will define several global variables that can be used in scripts that source this one
|
||||||
|
[string]$Global:RootDirectory
|
||||||
|
[string]$Global:ScriptsDirectory
|
||||||
|
[string]$Global:OutputDirectory
|
||||||
|
[string]$Global:ToolsDirectory
|
||||||
|
[string]$Global:LogsDirectory
|
||||||
|
[string]$Global:LogFile
|
||||||
|
|
||||||
## Setup the MSP management directories
|
## Setup the MSP management directories
|
||||||
If ( Test-Path ${Env:ProgramData} ) { $RootDirectory = "${Env:ProgramData}\${MSPName}" } Else { $RootDirectory = "${Env:SystemDrive}\${MSPName}" }
|
Function Setup-MSPDirectories {
|
||||||
$ScriptsDirectory = "${RootDirectory}\Scripts"
|
If ( Test-Path ${Env:ProgramData} ) { $Global:RootDirectory = "${Env:ProgramData}\${MSPName}" } Else { $Global:RootDirectory = "${Env:SystemDrive}\${MSPName}" }
|
||||||
$OutputDirectory = "${RootDirectory}\Output"
|
$Global:ScriptsDirectory = "${RootDirectory}\Scripts"
|
||||||
$ToolsDirectory = "${RootDirectory}\Tools"
|
$Global:OutputDirectory = "${RootDirectory}\Output"
|
||||||
$LogsDirectory = "${RootDirectory}\Logs"
|
$Global:ToolsDirectory = "${RootDirectory}\Tools"
|
||||||
|
$Global:LogsDirectory = "${RootDirectory}\Logs"
|
||||||
|
|
||||||
## Make sure all the management directories exist
|
## Make sure all the management directories exist
|
||||||
$RootDirectory, $ScriptsDirectory, $OutputDirectory, $ToolsDirectory, $LogsDirectory | ForEach-Object {
|
$RootDirectory, $ScriptsDirectory, $OutputDirectory, $ToolsDirectory, $LogsDirectory | ForEach-Object {
|
||||||
If ( !(Test-Path $_) ) {
|
If ( !(Test-Path $_) ) {
|
||||||
Try { New-Item -Path $_ -ItemType Directory -Force -ErrorAction SilentlyContinue | Out-Null }
|
Try { New-Item -Path $_ -ItemType Directory -Force -ErrorAction SilentlyContinue | Out-Null }
|
||||||
Catch { Write-Output $_.Exception.Message }
|
Catch { Write-Output $_.Exception.Message }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
## Function to get a datestamp for right now in a long format
|
||||||
|
Function Get-LongDateTime {
|
||||||
|
Return $(Get-Date -Format "yyyyMMddHHmmssffff")
|
||||||
}
|
}
|
||||||
|
|
||||||
## Setup the log file for messages generated when this script is run
|
## Setup the log file for messages generated when this script is run
|
||||||
$LogFilePrefix = "ManagementScript"
|
Function Setup-LogFile {
|
||||||
$LogFilePostfix = Get-Date -Format "yyyyMMddHHmmssffff"
|
$LogFilePrefix = "ManagementScript"
|
||||||
$LogFile = "${LogsDirectory}\${LogFilePrefix}_${LogFilePostfix}.log"
|
$LogFilePostfix = Get-LongDateTime
|
||||||
If ( !(Test-Path $LogFile) ) { New-Item -Path $LogFile -ItemType File -Force | Out-Null }
|
$Global:LogFile = "${LogsDirectory}\${LogFilePrefix}_${LogFilePostfix}.log"
|
||||||
|
|
||||||
## Delete log files older than 30 days
|
## Delete log files older than 30 days
|
||||||
$LogFileAllowedAge = (Get-Date).AddDays(-30)
|
$LogFileAllowedAge = (Get-Date).AddDays(-30)
|
||||||
Get-ChildItem -Path "${LogsDirectory}\${LogFilePrefix}_*.*" -Filter '*.log' | Where-Object {$_.LastWriteTime -lt $LogFileAllowedAge} | Remove-Item -Force -ErrorAction SilentlyContinue | Out-Null
|
Try {
|
||||||
|
Get-ChildItem -Path "${LogsDirectory}\${LogFilePrefix}_*.*" -Filter '*.log' | `
|
||||||
|
Where-Object {$_.LastWriteTime -lt $LogFileAllowedAge} | `
|
||||||
|
Remove-Item -Force -ErrorAction SilentlyContinue | Out-Null
|
||||||
|
}
|
||||||
|
Catch { Write-Output $_.Exception.Message }
|
||||||
|
|
||||||
|
Try { If ( !(Test-Path $LogFile) ) { New-Item -Path $LogFile -ItemType File -Force | Out-Null } }
|
||||||
|
Catch { Write-Output $_.Exception.Message }
|
||||||
|
}
|
||||||
|
|
||||||
## Log a message to the log file
|
## Log a message to the log file
|
||||||
Function LogMsg {
|
Function LogMsg {
|
||||||
@@ -455,4 +479,7 @@ function Toggle-Log {
|
|||||||
$log.SaveChanges()
|
$log.SaveChanges()
|
||||||
}
|
}
|
||||||
Catch { LogMsg $_.Exception.Message }
|
Catch { LogMsg $_.Exception.Message }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Setup-MSPDirectories
|
||||||
|
Setup-LogFile
|
||||||
@@ -21,7 +21,7 @@ If ( Test-Path "${Env:ProgramFiles(x86)}\MspPlatform\RequestHandlerAgent\unins00
|
|||||||
}
|
}
|
||||||
|
|
||||||
## Remove Windows Software Probe
|
## Remove Windows Software Probe
|
||||||
If ( Test-Path "${ProgramFiles(x86)}\N-able Technologies\Windows Software Probe\bin\wsp.exe" ) {
|
If ( Test-Path "${ProgramFiles(x86)}\N-able Technologies\Windows Software Probe\" ) {
|
||||||
$ProductCode = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Node\N-able Technologies\Windows Software Probe").ProductCode
|
$ProductCode = (Get-ItemProperty -Path "HKLM:\SOFTWARE\Wow6432Node\N-able Technologies\Windows Software Probe").ProductCode
|
||||||
LogMsg "Uninstalling Windows Software Probe"
|
LogMsg "Uninstalling Windows Software Probe"
|
||||||
Try { Start-Process "msiexec.exe" -ArgumentList "/X {${ProductCode}} /qn" -Wait }
|
Try { Start-Process "msiexec.exe" -ArgumentList "/X {${ProductCode}} /qn" -Wait }
|
||||||
@@ -29,9 +29,11 @@ If ( Test-Path "${ProgramFiles(x86)}\N-able Technologies\Windows Software Probe\
|
|||||||
}
|
}
|
||||||
|
|
||||||
## Remove Windows Agent
|
## Remove Windows Agent
|
||||||
LogMsg "Attempting to uninstall N-Central Windows Agent"
|
If ( Test-Path "${ProgramFiles(x86)}\N-able Technologies\Windows Agent\" ) {
|
||||||
Try { Start-Process "msiexec.exe" -ArgumentList "/X{F5873D07-85EE-4010-A461-B60989884B1C} /qn" -Wait }
|
LogMsg "Uninstalling N-Central Windows Agent"
|
||||||
Catch { LogErr $_.Exception.Message }
|
Try { Start-Process "msiexec.exe" -ArgumentList "/X{F5873D07-85EE-4010-A461-B60989884B1C} /qn" -Wait }
|
||||||
|
Catch { LogErr $_.Exception.Message }
|
||||||
|
}
|
||||||
|
|
||||||
## Remove NablePatchRepositoryService
|
## Remove NablePatchRepositoryService
|
||||||
$ServiceName = "NablePatchRepositoryService"
|
$ServiceName = "NablePatchRepositoryService"
|
||||||
|
|||||||
Reference in New Issue
Block a user