Files
Chronometer/BuildTasks/Uninstall.Task.ps1
Kevin Marquette dcb3f40371 Initial commit
2018-03-25 15:39:30 -07:00

29 lines
929 B
PowerShell

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
}
}