How To Connect To & Control Azure From Your Mac Using PowerShell
To connect to your Microsoft Azure subscription and use Power Shell from your Mac, you need to follow these steps:
1 — Go to https://brew.sh/ and follow the instructions for installing brew on your MacOS system. Make sure the installation is successful before moving to the next step.
2 — Open a new terminal window and run “brew — update”
3 — From the terminal window, run “sudo pwsh”. You will be prompted for your admin password. After you supply the correct system password, you will be taken to the PowerShell prompt. The prompt should change from your normal macsysname ~% prompt to a new prompt that begins with PS and looks something like this: PS /Users/yourusername.
NOTE: If you forget to elevate privileges with sudo, the PowerShell will start and appear to work normally, but as you run the command in step 4, you will most likely get errors. If you are still getting errors using the sudo command, see the troubleshooting section at the bottom of this article.
4 — From the PowerShell prompt, run the following command “Install-Module -Name Az -Repository PSGallery -Force”
Be patient and after the install completes it will notify you.
5 — To ensure your Az module is up to date, run the following command “Update-Module -Name Az -Force”
6 — Now you can connect to your Azure subscription using the “Connect-AzAccount” command from the PowerShell prompt. Run this command, and your default browser will open, prompting you to log into your Azure account.
Once you complete this successfully, you will see your Account Name, Subscription Name, and TenantId, and you will know you have successfully logged into your account.
7 — Now, you can ditch the web browser and control your Azure account from the command line on your Mac.
Refer to the PowerShell command reference for a complete list of commands you can execute, but assuming you have at least one resource in your Azure account, you can run the command “Get-AzResource,” and it should return a list of all your current resources.
This information is helpful for day-to-day administration tasks and most Azure certification exams (e.g., AZ-104 Azure Certified Administrator).
Get notified when I publish new articles. I never share your email address and your subscription is only used to send you a notification when I publish new articles.
Troubleshooting
The error message you’re encountering while trying to install the Azure PowerShell module ( Az
) in step 4 on your MacOS machine could involve one or more of the issues listed below:
Sudo Rights Requirement:
The warning about sudo rights indicates that the PowerShell session does not have the necessary permissions to install modules in the specified directory (/Users/mbpro23/.config/NuGet
). This is a common security feature in Unix-based systems like MacOS, where administrative privileges are required to install software system-wide. To resolve this, you have two options:
- Run PowerShell with sudo (administrative privileges). This can be done by opening your terminal and typing
sudo pwsh
, then running the install command again. - Use the
-Scope CurrentUser
parameter in your command to install the module only for the current user. This doesn't require administrative privileges. The command would be:Install-Module -Name Az -Repository PSGallery -Force -Scope CurrentUser
.
Unable to Resolve Package Source:
The warning Unable to resolve package source 'https://www.powershellgallery.com/api/v2'
suggests a problem with accessing the PowerShell Gallery. This could be due to network issues, PowerShell Gallery being down, or a misconfiguration in your system's network settings (like a proxy or firewall blocking access). Here are steps to troubleshoot this:
- Check your internet connection and ensure you can access other websites.
- Try accessing the URL
https://www.powershellgallery.com/api/v2
directly in a web browser to see if it's reachable. - If you’re behind a proxy or firewall, ensure that it’s configured to allow access to the PowerShell Gallery.
- Run
Get-PSRepository
to check the configured repositories in PowerShell and ensure that PSGallery is listed and configured correctly.
No Match Found for Module:
The error No match was found for the specified search criteria and module name 'Az'
often results from the inability to access the PowerShell Gallery, as discussed in point 2. Once you resolve the access issue, this error should also be resolved.
By addressing these points, you should be able to successfully install the Az
module on your MacOS system.
You can also connect with me on my website at https://timlayton.cloud