Bobcares

How to Uninstall Azure ad PowerShell Module

by | Oct 4, 2020

Are you trying to uninstall the Azure ad PowerShell module? We can help you with it.

Here at Bobcares, we have seen several such PowerShell related queries as part of our Server Management Services for web hosts and online service providers.

Today, we’ll take a look at how to uninstall the Azure ad Powershell module.

 

How we uninstall azure ad PowerShell module

Now let’s see how our Support Engineers uninstall the Azure ad PowerShell module.

 

Uninstall the Az PowerShell module from MSI

If you have installed the Az PowerShell module using the MSI package then you would need to uninstall it through the Windows System.

In Windows 10, you can uninstall it by clicking on Start >> Apps.

In Windows 7,8, you can uninstall it by Clicking on Start >> Control Panel >> Programs >> Uninstall a program.

Once you have reached this screen then you will see the Azure PowerShell in the program listing. You would need to uninstall this app.

 

Uninstall the Az PowerShell module from PowerShellGet

In order to uninstall the Az modules, we can use the Uninstall-Module cmdlet. However, the Uninstall-Module will only uninstall a single module. So in order to remove the Az PowerShell module completely then you would need to uninstall all the modules individually.

Run the below command to check the version of the Az PowerShell module

Get-InstalledModule -Name Az -AllVersions

The below script will uninstall the correct version of each submodule. However, to run this script you need administrator access.

function Uninstall-AzModule {
[CmdletBinding(SupportsShouldProcess)]
param(
[ValidateNotNullOrEmpty()]
[ValidateSet('Az','AzureRM','Azure')]
[string]$Name = 'Az',

[Parameter(Mandatory)]
[string]$Version,

[switch]$AllowPrerelease
)

$Params = @{}

if ($PSBoundParameters.AllowPrerelease) {
$Params.AllowPrerelease = $true
}

$IsAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] 'Administrator')

if (-not(Get-InstalledModule -Name $Name -RequiredVersion $Version -ErrorAction SilentlyContinue -OutVariable RootModule @Params)) {

Write-Warning -Message "Uninstall aborted. $Name version $Version not found."

} elseif (($RootModule.InstalledLocation -notlike "*$env:USERPROFILE*") -and ($IsAdmin -eq $false)) {

Write-Warning -Message "Uninstall aborted. $Name version $Version exists in a system path. PowerShell must be run elevated as an admin to remove it."

} elseif ((Get-Process -Name powershell, pwsh -OutVariable Sessions -ErrorAction SilentlyContinue).Count -gt 1) {

Write-Warning -Message "Uninstall aborted. Please close all other PowerShell sessions before continuing. There are currently $($Sessions.Count) PowerShell sessions running."

} else {
Write-Verbose -Message 'Creating list of dependencies...'
$target = Find-Module -Name $Name -RequiredVersion $Version @Params

$AllModules = @([pscustomobject]@{
Name = $Name
Version = $Version
})

$AllModules += foreach ($dependency in $target.Dependencies) {
switch ($dependency.keys) {
{$_ -contains 'RequiredVersion'} {$UninstallVersion = $dependency.RequiredVersion; break}
{$_ -contains 'MinimumVersion'} {$UninstallVersion = $dependency.MinimumVersion; break}
}

[pscustomobject]@{
Name = $dependency.Name
Version = $UninstallVersion
}
}

[int]$i = 100 / $AllModules.Count

foreach ($module in $AllModules) {
Write-Progress -Activity 'Uninstallation in Progress' -Status "$i% Complete:" -PercentComplete $i
$i++

if (Get-InstalledModule -Name $module.Name -RequiredVersion $module.Version -ErrorAction SilentlyContinue @Params) {
Write-Verbose -Message "Uninstalling $($module.Name) version $($module.Version)"

Remove-Module -FullyQualifiedName @{ModuleName=$module.Name;ModuleVersion=$module.Version} -ErrorAction SilentlyContinue

try {
if ($PSCmdlet.ShouldProcess("$($module.Name) version $($module.Version)")) {
Uninstall-Module -Name $module.Name -RequiredVersion $module.Version -Force -ErrorAction Stop @Params
}
$State = 'Uninstalled'
} Catch {
$State = 'Manual uninstall required'
Write-Verbose -Message "$($module.Name) version: $($module.Version) may require manual uninstallation."
}

} else {
$State = 'Not found'
Write-Verbose -Message "$($module.Name) version: $($module.Version) not found."
}

if (-not $PSBoundParameters.WhatIf) {
[pscustomobject]@{
ModuleName = $module.Name
Version = $module.Version
State = $State
}
}

}
}
}

Copy and paste the above script in your PowerShell session. The below example shows to remove an older version of the Az PowerShell module and its submodules.

Uninstall-AzModule -Name Az -Version 1.8.0

As the script runs, it displays the Name, Version, and State of each submodule that is being uninstalled.

 

Uninstall the AzureRM module

In case, if you have installed the Az module on your system and want to uninstall the AzureRM, then there are two ways to uninstall it. It completely depends on how you have installed it.

 

Uninstall the AzureRM PowerShell module from MSI

You can follow this method if you have installed the AzureRM PowerShell module using the MSI package. Here you would need to uninstall it through the Windows system.

In Windows 10, you can uninstall it by clicking on Start >> Settings >> Apps.

In Windows 7,8, you can uninstall it by Clicking on Start >> Control Panel >> Programs >> Uninstall a program.

Once you have reached this screen then you will see the Azure PowerShell or Microsoft Azure PowerShell – Month Year in the program listing. You would need to uninstall this app.

 

Uninstall the AzureRM PowerShell module from PowerShellGet

You can follow this method if you have installed the AzureRM PowerShell module using the PowerShellGet.

You can use the Uninstall-AzureRM cmdlet for uninstalling purposes.

Run the below command to remove all AzureRM modules from your machine. However, to run it you need to have the administrator privileges.

Uninstall-AzureRm

[Need any further assistance with PowerShell queries? – We are here to help you.]

 

Conclusion

Today, we saw how our Support Engineers uninstall the Az PowerShell module and AzureRM module from MSI and PowerShellGet.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF