Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Azure PowerShell Quick Start Guide

You're reading from   Azure PowerShell Quick Start Guide Deploy and manage Azure virtual machines with ease

Arrow left icon
Product type Paperback
Published in Dec 2018
Publisher Packt
ISBN-13 9781789614954
Length 118 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Thomas Mitchell Thomas Mitchell
Author Profile Icon Thomas Mitchell
Thomas Mitchell
Arrow right icon
View More author details
Toc

Installing Azure PowerShell

Performing management tasks within an Azure tenant, using PowerShell, requires a handful of prerequisites to be met first. For example, the AzureRM PowerShell module needs to be installed so that Azure PowerShell commands become available. However, since the preferred method of installing the AzureRM module is to do so via the PowerShell Gallery, the latest version of PowerShellGet needs to be installed first.

Once the latest versions of PowerShellGet and AzureRM are installed, the AzureRM module can be loaded and used to connect to the Azure tenant. The next few exercises will walk you through the installation of PowerShellGet, how to use it to download and install AzureRM, and then how to use AzureRM to connect to an Azure tenant.

Installing PowerShellGet

Before using PowerShell to deploy and manage virtual machines in Azure, you will need to install the Azure PowerShell module (AzureRM) on your workstation. The best way to install Azure PowerShell is to do it from the PowerShell Gallery, which is what you will learn to do in this section, starting with the installation of PowerShellGet.

The installation of PowerShellGet is necessary because PowerShellGet is the tool that is used to pull down PowerShell modules from the gallery—so, before doing anything, you need to ensure that you have the latest version of the PowerShellGet module (https://www.powershellgallery.com/) installed on your workstation. To check what version of PowerShellGet you have, run the Get-Module command, which is shown as follows:

Get-Module `
-Name PowerShellGet `
-ListAvailable | Select-Object -Property Name,Version,Path

The Get-Module command will list what versions of PowerShellGet are currently available on your workstation. By piping the results of the Get-Module command (using the | character) to the Select-Object command, you can view just the info you are looking for. In this case, you can see the Name, Version, and Path of each instance of PowerShellGet that currently resides on your machine:

To perform the exercises in this book, you are going to need PowerShellGet version 1.1.2.0 or later installed. If you don't have PowerShellGet version 1.1.2.0 or later installed, update it by running the Install-Module command, shown as follows:

Install-Module PowerShellGet -Force

The Install-Module command will update your PowerShellGet module to the latest version. Specifying the -Force switch simply suppresses any Are you sure? confirmation type messages. The following screenshot shows the installation of PowerShellGet:

Once the latest version of PowerShellGet is installed, you can install Azure PowerShell.

Installing the Azure PowerShell module

Before using PowerShellGet to download and install Azure PowerShell, you must first configure your PowerShell environment with an execution policy that allows scripts to run. Since the default execution policy for PowerShell is Restricted, you must change it by running the Set-ExecutionPolicy command:

Set-ExecutionPolicy -ExecutionPolicy RemoteSigned

Running the Set-ExecutionPolicy command, to set the execution policy to RemoteSigned, is sufficient for installing Azure PowerShell from the PowerShell Gallery. You could also set your policy to Unrestricted, but that would further open you up to unsigned commands that could be malicious. As you can see in the following screenshot, PowerShell will prompt you to confirm that you wish to change the execution policy:

Once your execution policy is set to RemoteSigned, you can install the AzureRM PowerShell module by running the Install-Module command:

Install-Module -Name AzureRM -AllowClobber

Running the preceding command launches the process of connecting to the PowerShell Gallery and downloading the Azure PowerShell module. The AllowClobber switch ensures that you get the full and complete installation of AzureRM.

As you can see in the following screenshot, the PowerShell Gallery is not configured as a trusted repository for PowerShellGet (you'd think it would be trusted by default). As such, you are likely to see a warning about the repository not being trusted, and you will be prompted whether you are sure you want to download the module. It's safe to answer Yes, or Yes to all, when you see this prompt.

Selecting Yes allows the installation of Azure PowerShell to continue:

The installation of Azure PowerShell is generally painless. The AzureRM module that gets installed is a rollup module for the Azure Resource Manager cmdlets. Installing the AzureRM module also pulls down, from the PowerShell Gallery, any Azure PowerShell module not previously installed.

Loading the AzureRM module

Once the Azure PowerShell module (AzureRM) has been installed, you can load the module into your PowerShell session using the Import-Module command. As per Microsoft's recommendations, you should do this in a non-elevated PowerShell session, so if you haven't done so already, open a new non-elevated PowerShell session and, from within this session, run the following command:

Import-Module -Name AzureRM

Importing the Azure PowerShell module is rather uneventful. However, rest assured that, unless an error message is displayed, you now have Azure PowerShell loaded—and now that you have Azure PowerShell installed and loaded, you can now actually connect to Azure using PowerShell.

Connecting to Azure via PowerShell

Although Azure PowerShell supports multiple login methods, the easiest way to get logged in is interactively at the command line, using the Connect-AzureRMAccount command. It's a simple command to run:

Connect-AzureRmAccount

After hitting Enter, a dialog box prompts you for your Azure admin credentials. Go ahead and supply your Azure admin credentials. Once you've supplied those credentials, you will be connected to your tenant:

To confirm that you are connected to your Azure tenant, you can run the Get-AzureRmSubscription command from PowerShell to confirm that it returns your subscription information:

Get-AzureRmSubscription

If the preceding command returns your subscription info, you can move on to the next steps.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime