Skip to content

Instantly share code, notes, and snippets.

@jaloplo
Created March 3, 2024 18:12
Show Gist options
  • Save jaloplo/f3b518f83032d700f58c38e1a0246107 to your computer and use it in GitHub Desktop.
Save jaloplo/f3b518f83032d700f58c38e1a0246107 to your computer and use it in GitHub Desktop.
PowerShell script for remove and uninstall a module from the current session.
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