Skip to content

Commit

Permalink
Add ability to actually remove the folders in the PowerShell Modules …
Browse files Browse the repository at this point in the history
…folders, when uninstalling ⭐
  • Loading branch information
blakedrumm authored Oct 7, 2024
1 parent 52d4fe5 commit 8fe0b83
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Powershell/Create-PortableSCOMPSModule.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ Write-Output "`$(Time-Stamp)Completed importing the SCOM PowerShell Module!"
}
elseif (`$Action -eq 'Uninstall')
{
# Remove GAC assemblies
Get-ChildItem "`$Path\Microsoft.EnterpriseManagement*" | % {
`$resolvedPath = (Resolve-Path `$gacPath\`$(`$_.Name) -ErrorAction SilentlyContinue)
if (`$resolvedPath)
Expand All @@ -286,23 +287,41 @@ elseif (`$Action -eq 'Uninstall')
}
}
# Remove Server folder
`$resolvedPath = Resolve-Path `$serverFolder -ErrorAction SilentlyContinue
if (`$resolvedPath)
{
Remove-Item -Path `$resolvedPath -Force -Recurse
}
# Remove Console folder
`$resolvedPath = Resolve-Path `$consoleFolder -ErrorAction SilentlyContinue
if (`$resolvedPath)
{
Remove-Item -Path `$resolvedPath -Force -Recurse
}
# Remove PowerShell folder
`$resolvedPath = Resolve-Path `$powerShellFolder -ErrorAction SilentlyContinue
if (`$resolvedPath)
{
Remove-Item -Path `$resolvedPath -Force -Recurse
}
# Remove the module path from PSModulePath environment variable
`$envVariableArray = [Environment]::GetEnvironmentVariable("PSModulePath", "Machine") -split ';'
if (`$envVariableArray -contains `$powerShellFolder)
{
`$envVariableArray = `$envVariableArray -ne `$powerShellFolder
`$newEnvVariable = `$envVariableArray -join ';'
[Environment]::SetEnvironmentVariable("PSModulePath", `$newEnvVariable, "Machine")
Write-Output "`$(Time-Stamp) - Removed module from the machine level environmental variable (PSModulePath)"
}
else
{
Write-Output "`$(Time-Stamp) - PowerShell module folder was not found in PSModulePath"
}
Write-Output "`$(Time-Stamp)Completed removing the SCOM PowerShell Module!"
}
"@
Expand Down

0 comments on commit 8fe0b83

Please # to comment.