unistall and install Azure powershell on mac

+1 vote
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 17 in Azure by Swapna
• 130 points
56 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 by Pearl

Related Questions In Azure

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
174 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 26, 2018 in Azure by null_void
• 3,220 points
51 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
• 56,940 points
3,211 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 21, 2018 in Azure by null_void
• 3,220 points
23 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
• 56,940 points
2,861 views
0 votes
1 answer

Is there a way to get ERROR details on Azure website?

You have two options: First, you can turn ...READ MORE

answered May 25, 2018 in Azure by club_seesharp
• 3,450 points
204 views
0 votes
1 answer

Are Docker and Azure Service Fabric both the same?

It's confusing since Docker (the company) is ...READ MORE

answered Jun 1, 2018 in Azure by null_void
• 3,220 points
666 views
0 votes
1 answer

How to choose between Azure App Service and Azure Service Fabric?

Microsoft has created the document with a comparison for ...READ MORE

answered Jun 13, 2018 in Azure by null_void
• 3,220 points
257 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
• 56,940 points
1,812 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 10, 2018 in Azure by club_seesharp
• 3,450 points
3,558 views