From 786ca1f983dea80ea27becc53d8dc93a86388b50 Mon Sep 17 00:00:00 2001 From: dyoder Date: Thu, 29 Jul 2021 12:57:11 -0400 Subject: [PATCH] added placeholder and paramset for deleting a service in Control-Service function added service removal in Uninstall-NCentralComponents.ps1 --- Tools.ps1 | 9 ++++++++- Uninstall-NCentralComponents.ps1 | 9 +++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Tools.ps1 b/Tools.ps1 index c1a686f..5cd852b 100644 --- a/Tools.ps1 +++ b/Tools.ps1 @@ -287,7 +287,7 @@ Function IsMemberOf { Return ([Security.Principal.WindowsPrincipal][System.Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole($Group) } -## Start, stop, or restart a list of services +## Start, stop, restart, or delete a list of services Function Control-Service { param( @@ -297,13 +297,17 @@ Function Control-Service [switch]$Stop, [Parameter(Mandatory=$true,ParameterSetName='restart')] [switch]$Restart, + [Parameter(Mandatory=$true,ParameterSetName='delete')] + [switch]$Delete, [Parameter(Mandatory=$true,ValueFromPipeline=$true,ParameterSetName='start')] [Parameter(Mandatory=$true,ValueFromPipeline=$true,ParameterSetName='stop')] [Parameter(Mandatory=$true,ValueFromPipeline=$true,ParameterSetName='restart')] + [Parameter(Mandatory=$true,ValueFromPipeline=$true,ParameterSetName='delete')] [string[]]$Name, [Parameter(Mandatory=$false,ParameterSetName='start')] [Parameter(Mandatory=$false,ParameterSetName='stop')] [Parameter(Mandatory=$false,ParameterSetName='restart')] + [Parameter(Mandatory=$false,ParameterSetName='delete')] [switch]$Match=$false ) switch ($PSCmdlet.ParameterSetName) { @@ -329,6 +333,9 @@ Function Control-Service Invoke-Expression $StartCmd Exit } + 'delete' { + ## Delete the service + } } ForEach ( $item in $Name ) { $service = Get-Service -Name $item -ErrorAction SilentlyContinue diff --git a/Uninstall-NCentralComponents.ps1 b/Uninstall-NCentralComponents.ps1 index c2efcea..e5d5221 100644 --- a/Uninstall-NCentralComponents.ps1 +++ b/Uninstall-NCentralComponents.ps1 @@ -28,6 +28,15 @@ If ( Test-Path "${ProgramFiles(x86)}\N-able Technologies\Windows Software Probe\ Catch { LogErr $_.Exception.Message } } +## Remove NablePatchRepositoryService +$Service = Get-Service -Name NablePatchRepositoryService -ErrorAction SilentlyContinue +If ( $Service.Length -gt 0 ) { + Control-Service -Stop -Name $Service.ServiceName + LogMsg "Deleting the service: ""NablePatchRepositoryService""" + Try { $Service | Remove-Service } + Catch { LogErr $_.Exception.Message } +} + ## Remove "MspPlatform" directory If ( Test-Path "${Env:ProgramFiles(x86)}\MspPlatform" ) { LogMsg "Forcefully removing ""${Env:ProgramFiles(x86)}\MspPlatform"""