unistall and install Azure powershell on mac

+2 votes
I have installed Azure commands on powershell on mac and I was able to run (Connect-AzAccount), it gave me the link to connect to azure portal with the code, so, it connected, but then, when I am trying to run any Azure commands like Get-AzResources or Ger-AzResourceGroup, it is saying "command not recognized" or "command was found in the module 'AzureRM.profile'., but the module could not be loaded. For more information, run 'Import-Module AzureRM.profile' ". Even after running the import-module  AzureRM.profile, I am getting the same error. Please help.

Looks like I need to unistall and reinstall Azure on powershell, can anyone please give me step by step instructions to unistall and reinstall azure powershell modules on Macbook air.

Thanks

I can only run Get-AzSubscription.
Oct 18, 2019 in Azure by Swapna
• 140 points
1,644 views

1 answer to this question.

0 votes

Hey start the uninstallation process by checking the available versions:

Get-InstalledModule -Name Az -AllVersions

Output:

Version             Name                           Repository           Description
-------             ----                           ----------           -----------
0.7.0               Az                             PSGallery            Azure Resource Manager Module
1.0.0               Az                             PSGallery            Azure Resource Manager Module

Get the list of dependent submodules:

function Uninstall-AllModules {
  param(
    [Parameter(Mandatory=$true)]
    [string]$TargetModule,

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

    [switch]$Force,

    [switch]$WhatIf
  )
  
  $AllModules = @()
  
  'Creating list of dependencies...'
  $target = Find-Module $TargetModule -RequiredVersion $version
  $target.Dependencies | ForEach-Object {
    if ($_.PSObject.Properties.Name -contains 'requiredVersion') {
      $AllModules += New-Object -TypeName psobject -Property @{name=$_.name; version=$_.requiredVersion}
    }
    else { # Assume minimum version
      # Minimum version actually reports the installed dependency
      # which is used, not the actual "minimum dependency." Check to
      # see if the requested version was installed as a dependency earlier.
      $candidate = Get-InstalledModule $_.name -RequiredVersion $version -ErrorAction Ignore
      if ($candidate) {
        $AllModules += New-Object -TypeName psobject -Property @{name=$_.name; version=$version}
      }
      else {
        $availableModules = Get-InstalledModule $_.name -AllVersions
        Write-Warning ("Could not find uninstall candidate for {0}:{1} - module may require manual uninstall. Available versions are: {2}" -f $_.name,$version,($availableModules.Version -join ', '))
      }
    }
  }
  $AllModules += New-Object -TypeName psobject -Property @{name=$TargetModule; version=$Version}

  foreach ($module in $AllModules) {
    Write-Host ('Uninstalling {0} version {1}...' -f $module.name,$module.version)
    try {
      Uninstall-Module -Name $module.name -RequiredVersion $module.version -Force:$Force -ErrorAction Stop -WhatIf:$WhatIf
    } catch {
      Write-Host ("`t" + $_.Exception.Message)
    }
  }
}

Remove older versions of powershell:

Uninstall-AllModules -TargetModule Az -Version 0.7.0 -Force

Output:

Creating list of dependencies...
Uninstalling Az.Profile version 0.7.0
Uninstalling Az.Aks version 0.7.0
Uninstalling Az.AnalysisServices version 0.7.0
...

Command to uninstall:

$versions = (Get-InstalledModule Az -AllVersions | Select-Object Version)
$versions[0..($versions.Length-2)]  | foreach { Uninstall-AllModules -TargetModule Az -Version ($_.Version) -Force }
answered Oct 22, 2019 by Pearl

Related Questions In Azure

0 votes
1 answer
0 votes
1 answer

How to install Azure CLI on Windows?

Hi@akhtar, For Windows, the Azure CLI is installed ...READ MORE

answered Nov 10, 2020 in Azure by MD
• 95,460 points
1,104 views
0 votes
1 answer

How to install Azure CLI on macOS?

Hi@akhtar, For the macOS platform, you can install ...READ MORE

answered Nov 13, 2020 in Azure by MD
• 95,460 points
1,388 views
0 votes
1 answer

How to upload a file on to Azure Blob storage without writing a code?

You can find the below tools useful ...READ MORE

answered Apr 13, 2018 in Azure by club_seesharp
• 3,450 points
1,606 views
0 votes
1 answer

Is there a logical difference between WebApp and API app in Azure?

Basically there was only minute differences between ...READ MORE

answered Apr 27, 2018 in Azure by null_void
• 3,220 points
1,222 views
0 votes
2 answers

How can I download a .vhd image to my local machine from azure and upload the same to a different azure account?

From the Windows Azure Portal you can ...READ MORE

answered Aug 20, 2018 in Azure by Priyaj
• 58,020 points
14,018 views
0 votes
1 answer

Where is the storage account name and access keys on the portal?

In the image under the connection string ...READ MORE

answered May 22, 2018 in Azure by null_void
• 3,220 points
684 views
0 votes
2 answers

How can I enable Ping(ICMP) on Azure?

I had a similar problem. Needed to ...READ MORE

answered Aug 17, 2018 in Azure by Priyaj
• 58,020 points
8,200 views
0 votes
2 answers

In Azure powershell Select-AzureSubscription command fetching error: the subscription name doesn't exist

The problem you're having is that the ...READ MORE

answered Aug 16, 2018 in Azure by Priyaj
• 58,020 points
7,678 views
0 votes
1 answer

How to configure kubectl command to access remote kubernetes cluster on azure?

Found a way to access remote kubernetes ...READ MORE

answered Aug 11, 2018 in Azure by club_seesharp
• 3,450 points
10,021 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP