@@ -277,6 +277,7 @@ Write-Output "`$(Time-Stamp)Completed importing the SCOM PowerShell Module!"
277
277
}
278
278
elseif (`$ Action -eq 'Uninstall')
279
279
{
280
+ # Remove GAC assemblies
280
281
Get-ChildItem "`$ Path\Microsoft.EnterpriseManagement*" | % {
281
282
`$ resolvedPath = (Resolve-Path `$ gacPath\`$ (`$ _.Name) -ErrorAction SilentlyContinue)
282
283
if (`$ resolvedPath)
@@ -286,23 +287,41 @@ elseif (`$Action -eq 'Uninstall')
286
287
}
287
288
}
288
289
290
+ # Remove Server folder
289
291
`$ resolvedPath = Resolve-Path `$ serverFolder -ErrorAction SilentlyContinue
290
292
if (`$ resolvedPath)
291
293
{
292
294
Remove-Item -Path `$ resolvedPath -Force -Recurse
293
295
}
294
296
297
+ # Remove Console folder
295
298
`$ resolvedPath = Resolve-Path `$ consoleFolder -ErrorAction SilentlyContinue
296
299
if (`$ resolvedPath)
297
300
{
298
301
Remove-Item -Path `$ resolvedPath -Force -Recurse
299
302
}
300
303
304
+ # Remove PowerShell folder
301
305
`$ resolvedPath = Resolve-Path `$ powerShellFolder -ErrorAction SilentlyContinue
302
306
if (`$ resolvedPath)
303
307
{
304
308
Remove-Item -Path `$ resolvedPath -Force -Recurse
305
309
}
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
+
306
325
Write-Output "`$ (Time-Stamp)Completed removing the SCOM PowerShell Module!"
307
326
}
308
327
"@
0 commit comments