From 201a7600419a289387aade66157d48e215c3c197 Mon Sep 17 00:00:00 2001 From: Stephan Yelle Date: Wed, 2 Jul 2025 21:52:12 -0400 Subject: [PATCH] Update StackMonkey.ps1 --- StackMonkey.ps1 | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/StackMonkey.ps1 b/StackMonkey.ps1 index 05be653..e07020a 100644 --- a/StackMonkey.ps1 +++ b/StackMonkey.ps1 @@ -219,32 +219,46 @@ function Perform-Cleanup { Write-LogHybrid "Cleanup mode enabled. Starting cleanup..." "Info" "SVSModule" - # Uninstall all versions of the module from all users + # Attempt to uninstall all versions of SVSMSP try { - Uninstall-Module -Name SVSMSP -AllVersions -Force -Confirm:$false + Uninstall-Module -Name SVSMSP -AllVersions -Force -Confirm:$false -ErrorAction Stop Write-LogHybrid "SVSMSP module uninstalled from system." "Success" "SVSModule" - } catch { - Write-LogHybrid "Failed to uninstall SVSMSP: $($_.Exception.Message)" "Error" "SVSModule" + } + catch { + # If no module was found, just warn and continue + if ($_.Exception.Message -match 'No match was found') { + Write-LogHybrid "No existing SVSMSP module found to uninstall." "Warning" "SVSModule" + } + else { + Write-LogHybrid "Failed to uninstall SVSMSP: $($_.Exception.Message)" "Error" "SVSModule" + } } - # Remove repository if you registered one + # Remove the custom repository if registered if (Get-PSRepository -Name SVS_Repo -ErrorAction SilentlyContinue) { try { - Unregister-PSRepository -Name SVS_Repo + Unregister-PSRepository -Name SVS_Repo -Confirm:$false -ErrorAction Stop Write-LogHybrid "SVS_Repo repository unregistered." "Success" "SVSModule" - } catch { + } + catch { Write-LogHybrid "Failed to unregister SVS_Repo: $($_.Exception.Message)" "Error" "SVSModule" } } # Finally, remove it from the current session if loaded if (Get-Module -Name SVSMSP) { - Remove-Module SVSMSP -Force - Write-LogHybrid "SVSMSP module removed from current session." "Success" "SVSModule" + try { + Remove-Module SVSMSP -Force -Confirm:$false -ErrorAction Stop + Write-LogHybrid "SVSMSP module removed from current session." "Success" "SVSModule" + } + catch { + Write-LogHybrid "Failed to remove SVSMSP from session: $($_.Exception.Message)" "Error" "SVSModule" + } } } + function Perform-ToolkitInstallation { Perform-Cleanup Write-LogHybrid "Registering repo $NewRepositoryName…" "Info" "SVSModule"