I love my MacBook Pro and I like to work on macOS (although Microsoft is bringing more and more of the features I love to Windows 10).
I'm also a big fan of Automation and Infrastructure as Code, especially when working with Cloud platforms such as Azure.
For that matter, I need to have PowerShell on macOS (Yes, Azure CLI is great and I use it frequently).
Fortunately, with PowerShell Core, Microsoft has brought the goodness of PowerShell to macOS and Linux.
In this post, I'll show you how easy it is to get going with PowerShell Core on your macOS box.
Installing PowerShell Core
You simply need to type this in a terminal:
dotnet tool install --global PowerShell
Installing the prerequisites
The prerequisites come down to .NET Core. In order to install it, simply download the installer from https://dotnet.microsoft.com/download. Then, it's only a matter of Continue, Continue, Install and Close. You would need at least version 2.2 of .NET Core.
Using PowerShell Core
You're now all set to use PowerShell Core. Simply fire up a terminal or Visual Studio Code and type the following:
pwsh
This will launch a PowerShell Core session.
When you want to end that session, simply type:
exit
Using Azure modules in PowerShell Core
Let's try to connect to Azure from my terminal on my macOS box.
For that matter, I'll need to install the Az.Accounts
module. So, here we go:
pwsh
install-module Az.Accounts
Now, let's login in to Azure:
Connect-AzAccount
And here we are: you can now manage your Azure resources using PowerShell Core right from within your macOS box!
Don't forget to import the modules required for what you're trying to do.
Conclusion
Today, PowerShell is available on a wide range of platforms and this is a good thing. PowerShell has, in my humble opinion, reconciled Windows IT Pros with scripting by offering them a way more powerful tool than they ever had.
By supporting macOS and Linux as well, they can also leverage those skills to these platforms.
See ya!
Top comments (4)
Hi Tidjani, to use the powersheel in MacOS, besides installing powershell core, do we also need to install azure cli?
No, you don't need to unless you're planning to use both.
Both will help you achieve the same thing. However, Azure CLI uses a syntax that is more familiar to those who used to use the Bash command line.
I would suggest to use Azure CLI over PS.Az unless you plan to write and run complex PS scripts. As a bonus the Azure CLI also works in your native Mac shell
Hey Alexander,
thanks for your comment. As I mentioned in the post, I use the Azure CLI on a regular basis too. As a bonus point, some of the Azure CLI commands are idempotent, whereas Azure PowerShell aren't.
The point here isn't to recommend one over the other. It is to highlight that whether you choose one or the other, you have the possibility to use them on Windows, macOS or Linux.
Keep in mind that Windows IT Pros are likely to be more used to PowerShell command line rather than a bash-based command line.
Cheers !
Tidjani