How to connect to Microsoft Azure using PowerShell

Share this:

In Today’s tutorial, we are going over the process to connect your Windows 10/Windows Server 2016 in Microsoft Azure to manage your tenant.

In the past, we had to install components on the Operating System (we may have if you are using older versions) to get the connection from your workstation to Microsoft Azure, but that is not the case with the latest OSes, such as Windows 10 and Windows Server 2016.

If you are studying for the exam 70-533: Implementing Microsoft Azure Infrastructure Solution or 70-535: Architecting Azure Solutions, it is good to understand and practice this process explained here.

Solution


The process to connect on Azure is done through the PowerShellGet module, and this module is responsible to interact with the PowerShell Gallery. You may be wondering what is PowerShell Gallery, right? It is a central repository for commands (modules) and DSC (Desired State Configuration) resources, you an find more about that by accessing this link here: https://www.powershellgallery.com

The first step, is to check the module installed locally, running the following cmdlet. The output of this cmdlet will provide information about the current version, brief description and where it is installed (the file itself).

Get-Module PowerShellGet –list | fl

image

Installing AzureRM Module..

Now that we have the means to download and use modules from the PowerShell Gallery, we can use the following cmdlet to install the AzureRM which will enable the cmdlets to manage services from Microsoft Azure.

Install-Module AzureRM

Make sure that you are running as administrator, and you may be asked to trust the repository, make sure that you confirm.

image

After confirmation the download of the dependent packages will continue, give some time and wait for completion.

image

In order to validate the current module (version and file), we can run the following cmdlet:

Get-Module AzureRM -list | fl

image

Managing Modules..

In some situations, the administrator may want to install a different version from the latest, using the following cmdlet we can install the version 5.0.0 for example.

Install-Module AzureRM -RequiredVersion 5.0.0

In order to load the module of any given version, we an run the following cmdlet.

Import-Module AzureRM -Version 5.0.0

The entire process of installing a specific version, listing all modules on the local machine and using a specific module are depicted in the image below.

image

Understanding Modules in PowerShell

If you are curious to see what is running on your current session, run the following cmdlet, and a list of all loaded modules will be listed.

Get-Module

To list all modules available for use in your machine, the following cmdlet can be used:

Get-Module –ListAvailable

image

Connecting to Microsoft Azure..

The final step is to connect to our Microsoft Azure tenant, and that can be done using the cmlet below and a prompt to authenticate will be displayed.

Add-AzureRMAccount

image

 

 

It is all about Security…

Security is a must, and we need to policy ourselves around security best practices and some potential risks that may be involved in any given process. Here are some of the topics from the top of my head that we should be aware in the topic covered in this tutorial. If you are studying for Security certifications that may give you in some insights:

  • If you are connecting to Microsoft Azure to manage, make sure that you have MFA (Multiple Factor Authentication) enabled
  • We are connecting to PowerShell Gallery, so make sure that your DNS resolution is working correctly, and you are not expose to DNS Spoofing (Pharming attack)
  • Just in case, if you are a security freak, check your host file to make sure that it is clean and not compromised as well
  • Last but not least, make sure that your machine is free of any malware and with the AV up-to-date.

Written by Anderson Patricio

Anderson Patricio

Anderson Patricio is a Canadian MVP in Cloud and Datacenter Management, and Office Server and Services, besides the Microsoft Award he also holds a Solutions Master (MCSM) in Exchange and several other certifications. Anderson has been contributing to the Microsoft Community with articles, tutorials, blog posts, twitter, forums and book reviews. He is a regular contributor here at ITPROCentral.com, MSExchange.org, Techgenix.com and Anderson Patricio.org (Portuguese).

Related Post

How to create a Virtual Network using Azure Resour... Configuring a Virtual Network and a VPN connection between Microsoft Azure and a local site using Azure Resource Manager deployment model. Solution ...
How to build a Disaster Recovery solution with Azu... Frequently I heard how to build a disaster recovery solution. When I heard that I always think about ASR. On my last post I talked about Azure Site Re...
Top 5 of the Week: Week of May 8th Folks, Here are the top 5 IT news for this week. Quick guide to Windows 10 training and certification for IT pros https://blogs.technet...
Azure enhancement Site-to-Site VPN functionality After Scott Guthrie announce the new enhancements on Azure, last May, I was very excited with one in particular. Multi Site-to-Site VPN. This enhancem...