Skip to content

Added uninstall for Azure.Storage module #1071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 6, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions tools/AzureRM/AzureRM.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ function Import-AzureRM

$AzureRMModules | ForEach {
$moduleName = $_
$matchedModule = Get-InstalledModule -Name $moduleName -MinimumVersion $_MinVer -MaximumVersion $_MaxVer -ErrorAction Ignore | where {$_.Name -eq $moduleName}
if ($matchedModule -ne $null) {
$_MatchedModule = Get-InstalledModule -Name $moduleName -MinimumVersion $_MinVer -MaximumVersion $_MaxVer -ErrorAction Ignore | where {$_.Name -eq $moduleName}
if ($_MatchedModule -ne $null) {
try {
Import-Module -Name $matchedModule.Name -RequiredVersion $matchedModule.Version -ErrorAction Stop
Import-Module -Name $_MatchedModule.Name -RequiredVersion $_MatchedModule.Version -ErrorAction Stop
Write-Output "$moduleName imported..."
} catch {
Write-Warning "Skipping $Name module..."
Expand All @@ -164,12 +164,15 @@ function Uninstall-ModuleWithVersionCheck([string]$Name,[string]$MajorVersion)
$_MinVer = "$MajorVersion.0.0.0"
$_MaxVer = "$MajorVersion.9999.9999.9999"
# This is a workaround for a bug in PowerShellGet that uses "start with" matching for module name
$matchedModule = Get-InstalledModule -Name $Name -MinimumVersion $_MinVer -MaximumVersion $_MaxVer -ErrorAction Ignore | where {$_.Name -eq $Name}
if ($matchedModule -ne $null) {
$_MatchedModule = Get-InstalledModule -Name $Name -MinimumVersion $_MinVer -MaximumVersion $_MaxVer -ErrorAction Ignore | where {$_.Name -eq $Name}
if ($_MatchedModule -ne $null) {
try {
Remove-Module -Name $matchedModule.Name -Force -ErrorAction Ignore
Uninstall-Module -Name $matchedModule.Name -RequiredVersion $matchedModule.Version -Confirm:$false -ErrorAction Stop
Write-Output "$Name uninstalled..."
Remove-Module -Name $_MatchedModule.Name -Force -ErrorAction Ignore
Uninstall-Module -Name $_MatchedModule.Name -RequiredVersion $_MatchedModule.Version -Confirm:$false -ErrorAction Stop
if ((Get-Module -Name $_MatchedModule.Name | where {$_.Version -eq $_MatchedModule.Version}) -eq $null)
{
Write-Output "$Name version $($_MatchedModule.Version) uninstalled..."
}
} catch {
Write-Warning "Skipping $Name package..."
Write-Warning $_
Expand Down Expand Up @@ -203,6 +206,7 @@ function Uninstall-AzureRM
Uninstall-ModuleWithVersionCheck $_ $MajorVersion
}

Uninstall-ModuleWithVersionCheck "Azure.Storage" $MajorVersion
Uninstall-ModuleWithVersionCheck "AzureRM.Profile" $MajorVersion
}

Expand Down