Skip to content

Commit 8fe0b83

Browse files
authored
Add ability to actually remove the folders in the PowerShell Modules folders, when uninstalling ⭐
1 parent 52d4fe5 commit 8fe0b83

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

Powershell/Create-PortableSCOMPSModule.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,7 @@ Write-Output "`$(Time-Stamp)Completed importing the SCOM PowerShell Module!"
277277
}
278278
elseif (`$Action -eq 'Uninstall')
279279
{
280+
# Remove GAC assemblies
280281
Get-ChildItem "`$Path\Microsoft.EnterpriseManagement*" | % {
281282
`$resolvedPath = (Resolve-Path `$gacPath\`$(`$_.Name) -ErrorAction SilentlyContinue)
282283
if (`$resolvedPath)
@@ -286,23 +287,41 @@ elseif (`$Action -eq 'Uninstall')
286287
}
287288
}
288289
290+
# Remove Server folder
289291
`$resolvedPath = Resolve-Path `$serverFolder -ErrorAction SilentlyContinue
290292
if (`$resolvedPath)
291293
{
292294
Remove-Item -Path `$resolvedPath -Force -Recurse
293295
}
294296
297+
# Remove Console folder
295298
`$resolvedPath = Resolve-Path `$consoleFolder -ErrorAction SilentlyContinue
296299
if (`$resolvedPath)
297300
{
298301
Remove-Item -Path `$resolvedPath -Force -Recurse
299302
}
300303
304+
# Remove PowerShell folder
301305
`$resolvedPath = Resolve-Path `$powerShellFolder -ErrorAction SilentlyContinue
302306
if (`$resolvedPath)
303307
{
304308
Remove-Item -Path `$resolvedPath -Force -Recurse
305309
}
310+
311+
# Remove the module path from PSModulePath environment variable
312+
`$envVariableArray = [Environment]::GetEnvironmentVariable("PSModulePath", "Machine") -split ';'
313+
if (`$envVariableArray -contains `$powerShellFolder)
314+
{
315+
`$envVariableArray = `$envVariableArray -ne `$powerShellFolder
316+
`$newEnvVariable = `$envVariableArray -join ';'
317+
[Environment]::SetEnvironmentVariable("PSModulePath", `$newEnvVariable, "Machine")
318+
Write-Output "`$(Time-Stamp) - Removed module from the machine level environmental variable (PSModulePath)"
319+
}
320+
else
321+
{
322+
Write-Output "`$(Time-Stamp) - PowerShell module folder was not found in PSModulePath"
323+
}
324+
306325
Write-Output "`$(Time-Stamp)Completed removing the SCOM PowerShell Module!"
307326
}
308327
"@

0 commit comments

Comments
 (0)