PowerShell Basics: How to Manage Azure Resources via PowerShell
Published Nov 28 2019 12:01 AM 9,065 Views
Microsoft

PowerShell automation can be powerful when harnessed correctly.  Whats more is that its capabilities can expand well beyond on-premises. To get started on this journey, this post will look at how to manage Azure Resources via PowerShell to further our learning on adoption and successfully set the foundation for future enablement.  The PowerShell module installed will be AzureRM which allows for management of both Azure and Azure Stack. This does differ from installing Az modules which only currently support Azure. Further details surrounding this can be found here

 

Lets begin.

 

    1. Run PowerShell in Administrator mode
       
      Run PowerShell Force AzureAD Password SyncRun PowerShell Force AzureAD Password Sync 
    2. Next run the following command to verify if the module is already installed:
       
      Get-Module -ListAvailable | Where-Object -Property Name -Like "*Azure*"

      NOTE: Verification entails that no modules are listed
       

    3. Next install the AzureRM module by running the following command: 

      Install-Module -Name AzureRM

       

    4. Enter Y and press enter at the NuGet provider prompt to ensure the latest version in installed.

      NOTE: This will take some time to install
       
    5. At the Untrusted repository prompt, enter Y and press enter:
       
      How_to_Manage_Azure_Resources_via_PowerShell_001How_to_Manage_Azure_Resources_via_PowerShell_001
      NOTE: This allows the ability to install packages from PowerShellGallery.com. This will also take some time to install.
       
    6. Run the following command to connect to your Azure subscription: 

      Connect-AzureRmAccount

       

    7. At the Untrusted Publisher prompt, enter A and press enter:
       
      How_to_Manage_Azure_Resources_via_PowerShell_002How_to_Manage_Azure_Resources_via_PowerShell_002
      NOTE:  This allows the ability to run packages from PowerShellGallery.com.
       
    8. Enter your username and password to sign into your Azure subscription
       
      How_to_Manage_Azure_Resources_via_PowerShell_003How_to_Manage_Azure_Resources_via_PowerShell_003
      NOTE: Details of said Azure subscription are shown once authentication is successful
       
    9. To verify that the connection is successful, run the following command to list the subscription's resource groups: 

      Get-AzureRmResourceGroup | Select-Object -Property ResourceGroupName,Location

       

    10. Run the following command to add PowerShellGallery.com as a trusted repository to quicken future module updates:
       
      Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
      Get-PSRepository


That completes the setup of the AzureRM module in PowerShell.  Future blog posts will now expand on specific management of Azure Resources using this post as a prerequisite. 

2 Comments
Copper Contributor

Surprised to see someone from MS suggest AzureRM at this point, given the recommendation to upgrade to AZ 'as soon as possible'

Microsoft

@JoshuaK AzureRM will continue to be supported and receive bugfixes through December 2020. Microsoft also advises the use of AzureRM in Azure Stack for the time being. This is also shared within the beginning of this paragraph of this post.

Version history
Last update:
‎Nov 27 2019 11:03 AM
Updated by: