Cloud Powershell Modules

Introduction When working in Azure or the Microsoft Cloud environments in general, you will experience that most information are accessible using Powershell. However, there is a catch in regards to what the different modules provides. When you are done reading this post, you should have a better understanding about which modules connects to which areas […]
8 jun, 2022

Introduction

When working in Azure or the Microsoft Cloud environments in general, you will experience that most information are accessible using Powershell. However, there is a catch in regards to what the different modules provides.

When you are done reading this post, you should have a better understanding about which modules connects to which areas in Azure and Exchange online and how they will be able to help you in your quest for daily maintenance or scripting of tasks.

For those of you who don’t know what a module is here is the short version of an explanation. A module is basically a package containing cmdlets and aliases that can be used to create, read, change or delete dependent on the purpose of the specific module.

All of the described modules are publicly available by use of the install-module command.

But let’s get to it, shall we?

AZ Modules


The AZ modules is the current Azure powershell modules. The AZ modules supersedes the older AzureRM modules as the current module to manage and build resources in Azure, using powershell.

If you find a script or have legacy scripts where the command “azurerm” is used, you will in most cases be able to find the exact same command by replacing azurerm with az.

You can install the modules directly from powershell using one of the below commands.

After the module is installed, you will need to connect. If you have a user that only have access to one specific tenant, all you have to do is to connect using the following command.

However, if you have access to multiple tenants you will soon learn that you can see subscriptions across all tenants. So for instance if I run connect-azaccount and connects, and following that runs the “Get-AzSubscription” you will notice that this shows subscriptions across 3 different tenants.

This is one of the details that makes the az modules special, since they do not connect to a specific tenant but can connect to all tenants where the specific user has access with the privileged that the user has in the given tenant.

To connect to a specific tenant, and perhaps even a specific subscription, we need to specify the tenant and subscription that we wishes to work on. This can be done by either connecting and then selecting the right subscription or by connecting to the correct subscription and tenant on the connection cmdlet like this

The Az module is split up into 75 submodules, that will be installed when running the above command. Each submodule is designed to handle a specific subsection of commands.

So for instance the az.compute module is designed to handle everything related to virtual machine creation and maintenance in Azure. But we do not have to specify which module to use when utilizing the az module, so if we wish to create a VM right now, and we don’t care about anything but the name, we could simply run the following command.

Which will create a VM named “MyVm” in the subscription where we are currently located, in a resource group named “MyVm”.

To create an example. A VM in Azure like most resources are attached to a subscription. If we run the get-azvm we will only be shown the specific VM’s in a given subscription, but if we wish to see all VM’s in a tenant or a selection of subscriptions, we need to run through all subscriptions, one by one to get the data we needs.

The result of the above script would be an array containing all the servers in this specific test tenant that I ran this on.

However, not all modules are installed with the base package. In total, there are 163 different az.* modules, but of these only 75 are included when installing the az module. So for some resources or information it requires us to install a module manully. An example of one of the missing modules is the az.costmanagement. If you for some reason requires the features in one of these packages you can install them using the install-module command.

Exchange Online

For everyone working in Exchange online the powershell tools are a must. Not only are there a lot of settings that can only be changed using powershell, but reading data from the users or bulk changes are done a lot faster using powershell than ECP, not to mention the advantage of sourcing data from different sources into the same output.

First things first, to install the module, you have to download it from the powershell gallery

Once it’s installed, you connect to your environment using the connect-ExchangeOnline cmdlet. You can either connect to your own tenant, or to a tenant where your user have the appropriate rights for exchange management.

And from there, we can start handling everything such as creation, changing or simple get operations or pulling data for reports.

So what can we use this module for? Well, a lot of things. It’s used to bulk migrate user, see status for migrations, enable access to shared mailboxes, or even as a central way as configuring access to all users calendars.

So let’s take an example, the following script exports all calendar permissions set on the users calendars. It does this by first finding all mailboxes in the organization, and then run through them one by one for calendar permissions.

The output of that code is an exported csv file, that would look something like this and which would provide an overview of all calendar permissions in that specific organization

MSOL

MSOL is a bit hard to explain – it’s still nessesary in many cases, but at the same time it’s being deprecated some time in the future. It holds a lot of the same data azure the AzureAD and ExchangeOnline module, but still contains some variables that are not present in those modules.

So you might not need it, but there is no guarantee.

The module can be downloaded from the powershell gallery

When it’s installed, you have to connect to the module. To connect you can run the following command

Basically, if there is user information you can’t find on the two previously named modules, msol can be your saviour.

Final thoughts

This is only a select few of the modules in existence for your cloud services, but given the area that I work in, these are the ones I use the most.

Each of them have an area in Microsoft Cloud Environments where they are the powershell tool at hand for handling and solving both incidents and day to day maintenance.

About Martin Meiner Tästensen

I am a positive minded It professional, with more than 10 years of experience in various IT roles. I love to build, create and see how an idea can become a system affecting hundreds or thousands of employees – and at the same time try to make the system work as smooth as possible to give the best end user experience. My Primary focus for the first decade of my career has been towards classic infrastructure where I worked with a deep knowledge level on both network and servers – where the latter has ranged from physical servers, over OS layer and all the way to the services installed on the server.

Related articles

You might also like..