Initial commit
This commit is contained in:
28
BuildTasks/Uninstall.Task.ps1
Normal file
28
BuildTasks/Uninstall.Task.ps1
Normal file
@@ -0,0 +1,28 @@
|
||||
|
||||
task Uninstall {
|
||||
'Unloading Modules...'
|
||||
Get-Module -Name $ModuleName -ErrorAction 'Ignore' | Remove-Module
|
||||
|
||||
'Uninstalling Module packages...'
|
||||
$modules = Get-Module $ModuleName -ErrorAction 'Ignore' -ListAvailable
|
||||
foreach ($module in $modules)
|
||||
{
|
||||
Uninstall-Module -Name $module.Name -RequiredVersion $module.Version -ErrorAction 'Ignore'
|
||||
}
|
||||
|
||||
'Cleaning up manually installed Modules...'
|
||||
$path = $env:PSModulePath.Split(';').Where({
|
||||
$_ -like 'C:\Users\*'
|
||||
}, 'First', 1)
|
||||
|
||||
$path = Join-Path -Path $path -ChildPath $ModuleName
|
||||
if ($path -and (Test-Path -Path $path))
|
||||
{
|
||||
'Removing files... (This may fail if any DLLs are in use.)'
|
||||
Get-ChildItem -Path $path -File -Recurse |
|
||||
Remove-Item -Force | ForEach-Object 'FullName'
|
||||
|
||||
'Removing folders... (This may fail if any DLLs are in use.)'
|
||||
Remove-Item $path -Recurse -Force
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user