"So you want to get to know Azure?..." How to install and configure Azure PowerShell on macOS for use in managing an Azure subscription
So you want to get to know Azure?

"So you want to get to know Azure?..." How to install and configure Azure PowerShell on macOS for use in managing an Azure subscription

I am writing a new series of articles (1 a week) that will help you to explore the Microsoft Azure platform. The whole series is called "So you want to get to know Azure?...". These articles will cover a wide variety of topics from the most basic to the most advanced aspects of Azure. Feel free to use them to enhance your Azure experience! - Good Luck and may Azure be with you always....

Article #1

======================================================

NOTE: This article assumes that you already have an Azure Subscription that is active and available. If you do not, go here:

https://azure.microsoft.com/en-us/free/

Follow the instructions to create a free account and begin using Azure.

======================================================

Step 1: Install PowerShell Core v6 - (Homebrew or Direct Download)

Installation via Homebrew - macOS 10.12

Homebrew is “the missing package manager for macOS”. If the brew command is not found, you need to install Homebrew following these instructions.

Once you have installed Homebrew, installing PowerShell is easy. First, install Homebrew-Cask, so you can install more packages:

brew tap caskroom/cask

Now, you can install PowerShell:

brew cask install powershell

When new versions of PowerShell are released, simply update Homebrew's formulae and upgrade PowerShell:

brew update

brew cask reinstall powershell

Note: because of this issue in Cask, you currently have to do a reinstall to upgrade.


Installation via Direct Download - macOS 10.12

Using macOS 10.12, download the PKG package powershell-6.0.1-osx.10.12-x64.pkg from the releases page onto the macOS machine.

Either double-click the file and follow the prompts, or install it from the terminal:

sudo installer -pkg powershell-6.0.1-osx.10.12-x64.pkg -target /

  

Uninstallation - macOS 10.12

If you installed PowerShell with Homebrew, uninstallation is easy:

brew cask uninstall powershell

If you installed PowerShell via direct download, PowerShell must be removed manually:

sudo rm -rf /usr/local/bin/pwsh /usr/local/microsoft/powershell

To uninstall the additional PowerShell paths (such as the user profile path) remove the desired the paths with sudo rm. (Note: this is not necessary if you installed with Homebrew.)

 Paths

·      $PSHOME is /opt/microsoft/powershell/6.0.1/

·      User profiles will be read from ~/.config/powershell/profile.ps1

·      Default profiles will be read from $PSHOME/profile.ps1

·      User modules will be read from ~/.local/share/powershell/Modules

·      Shared modules will be read from /usr/local/share/powershell/Modules

·      Default modules will be read from $PSHOME/Modules

·      PSReadline history will be recorded to ~/.local/share/powershell/PSReadLine/ConsoleHost_history.txt

The profiles respect PowerShell's per-host configuration, so the default host-specific profiles exists at Microsoft.PowerShell_profile.ps1 in the same locations.

On Linux and macOS, the XDG Base Directory Specification is respected.

Note that because macOS is a derivation of BSD, instead of /opt, the prefix used is /usr/local. Thus, $PSHOME is /usr/local/microsoft/powershell/6.0.1/, and the symlink is placed at /usr/local/bin/pwsh.

Step 2: Install Azure PowerShell for .NET Core

PowerShell Core v6 comes with the PowerShellGet module already installed. This makes it easy to install any module that is published to the PowerShell Gallery. To install Azure PowerShell, open a new PowerShell session and run the following command:

Install-Module AzureRM.NetCore

 Step 3: Load the AzureRM.Netcore module

Once the module is installed, you need to load the module into your PowerShell session. Modules are loaded using the Import-Module cmdlet, as follows:

Import-Module AzureRM.Netcore

Import-Module AzureRM.Profile.Netcore

After the import completes, you can test your newly installed and module by attempting to sign into Azure using the following command:

Login-AzureRMAccount

The above command should prompt you to go to https://aka.ms/devicelogin and enter the provided code.

Once the code is entered, you will be asked to either select or provide an account credential to authenticate your session against the Azure subscription. Then you should be all set to start using PowerShell.


Good Luck...

You can follow me on Twitter: @Adam_ITProTV


 

要查看或添加评论,请登录

社区洞察