Mastering Windows Server 2016 Hyper-V

(Romina) #1

infrastructure person, and because PowerShell is used throughout the book, I’m going
to spend a few pages looking at using PowerShell to manage Azure resources.


Two separate sets of Azure PowerShell modules are available: one for Azure Service
Manager (Azure) and one for Azure Resource Manager (AzureRM). In this section, I
focus on using the AzureRM module with Azure Resource Manager resources.
Installation is covered in detail at https://azure.microsoft.com/en-
us/documentation/articles/ powershell-install-configure/, but it can easily be
installed from the PowerShell Gallery by using the following command from an
elevated PowerShell session:


Install-Module AzureRM


The Install-Module command utilizes the NuGet provider, and you will be prompted
if the NuGet provider can be installed. Select Yes, and the installation will continue.
Microsoft updates the Azure modules frequently. To update to the latest version at
any time, use this command:


Update-Module AzureRM


After they are imported, if you run the following command, you will get some idea of
the scope of the AzureRM cmdlets:


Get-Module –ListAvailable Azure*


You will notice that a huge number of modules were installed, related to all aspects of
Azure, including Backup, Compute, Networking, storage, and more. There is no need
to perform an Import-Module manually with PowerShell 3 and above, as modules are
autoloaded as required.


The first step is to authenticate to Azure to enable access to your resources. For
AzureRM, this is achieved via the Login-AzureRmAccount cmdlet that will open a dialog
box to enable credentials to be entered.


Once you have authenticated to Azure, you can view the list of subscriptions to which
you have access and select one as the default, which is what future cmdlet operations
will be performed against.


Get-AzureRmSubscription
Select-AzureRmSubscription -SubscriptionId


Azure is made up of resource providers to provide services. These can all be directly
viewed with the code that follows, and then the actual services within a resource
provider, such as for the Compute resource provider.


Get-AzureRmResourceProvider
Get-AzureRmResourceProvider -ProviderNamespace Microsoft.Compute


The resource providers can be used to check where services are offered. For example,
to check where IaaS VMs are available:

Free download pdf