Created
March 3, 2024 18:12
-
-
Save jaloplo/f3b518f83032d700f58c38e1a0246107 to your computer and use it in GitHub Desktop.
PowerShell script for remove and uninstall a module from the current session.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param ( | |
[Parameter(Mandatory=$true)] | |
[string]$moduleName | |
) | |
# Check if the module is imported | |
$moduleImported = Get-Module -Name $moduleName -ErrorAction SilentlyContinue | |
if ($moduleImported) { | |
Write-Host "Unimporting module '$moduleName'..." | |
# Unimport the module | |
Remove-Module -Name $moduleName -Force | |
} else { | |
Write-Host "Module '$moduleName' is not imported." | |
} | |
# Check if the module is installed | |
$moduleInstalled = Get-Module -Name $moduleName -ListAvailable | |
if ($moduleInstalled) { | |
Write-Host "Uninstalling module '$moduleName'..." | |
# Uninstall the module | |
Uninstall-Module -Name $moduleName -Force | |
} else { | |
Write-Host "Module '$moduleName' is not installed." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment