AzureTip #01 – Azure PowerShell Provider

A Windows PowerShell provider allows any data store to be exposed like a file system as if it were a mounted drive. Below are some examples:

  • File System
  • Registry
  • Certificate Store

In order to manage these providers, you can use the Get-PSDrive cmdlet.  Use this cmdlet to get the drives mounted (and the PS Provider) in the current session:

PS > Get-PSdrive

Name           Used (GB)     Free (GB) Provider      Root                                                                        CurrentLocation
----           ---------     --------- --------      ----                                                                        ---------------
Alias                                  Alias
C                 324.12        110.45 FileSystem    C:\                                                                           Users\Nicolas
Cert                                   Certificate   \
Env                                    Environment
Function                               Function
HKCU                                   Registry      HKEY_CURRENT_USER
HKLM                                   Registry      HKEY_LOCAL_MACHINE
Variable                               Variable
WSMan                                  WSMan

Thanks to the AzurePSDrive PowerShell Module, you can mount a drive in order to navigate to your Azure Resources. You only need to have Windows PowerShell 5 or higher.

First, install the PowerShell Module from the PowerShell Gallery:

PS > Install-Module AzurePSDrive

Then, import the module:

PS > Import-Module AzurePSDrive

Now, you must login with your Azure Account:

PS > Login-AzureRmAccount

Environment           : AzureCloud
Account               : contact@get-cmd.com
TenantId              : xxxxxxxxxxxxxxxxxx
SubscriptionId        : xxxxxxxxxxxxxxxxxx
SubscriptionName      : Visual Studio Enterprise
CurrentStorageAccount :

We can create the Azure PSDrive using the SHiPS provider:

PS > New-PSDrive -Name AzureCloud -PSProvider SHiPS -root 'AzurePSDrive#Azure'

Name           Used (GB)     Free (GB) Provider      Root                                                                        CurrentLocation
----           ---------     --------- --------      ----                                                                        ---------------
AzureCloud                             SHiPS         AzurePSDrive#Azure

Finally, we can nagivate to the Azure subscription:

PS > cd AzureCloud:
PS AzureCloud:\> gci


    Directory: AzureCloud:


Mode SubscriptionName         SubscriptionId              TenantId                  State
---- ----------------         --------------              --------                  -----
+    Visual Studio Enterprise xxxxxxxxxxxxxxxxxxxxxxxxx   xxxxxxxxxxxxxxxxxxxxxxxxx Enabled

Great, now we can browse our Azure Resources:

PS AzureCloud:\> cd '.\Visual Studio Enterprise\'
PS AzureCloud:\Visual Studio Enterprise> gci


    Directory: AzureCloud:\Visual Studio Enterprise


Mode Name
---- ----
+    AllResources
+    ResourceGroups
+    StorageAccounts
+    VirtualMachines
+    WebApps


PS AzureCloud:\Visual Studio Enterprise> gci .\ResourceGroups\


    Directory: AzureCloud:\Visual Studio Enterprise\ResourceGroups


Mode ResourceGroupName              Location   ProvisioningState Tags
---- -----------------              --------   ----------------- ----
+    cloud-shell-storage-westeurope westeurope Succeeded
+    DefaultResourceGroup-WEU       westeurope Succeeded
+    Nico-RG01                      westeurope Succeeded
+    RG001                          westeurope Succeeded
+    RG002                          westeurope Succeeded


PS AzureCloud:\Visual Studio Enterprise>

More information about SHiPS: https://www.powershellgallery.com/packages/SHiPS/0.3.0

 

Thanks for reading! You can follow me on Twitter @PrigentNico

About Nicolas 282 Articles
I work as an IT Production Manager, based in Paris (France) with a primary focus on Microsoft technologies. I have 10 years experience in administering Windows Servers. . I am a Microsoft MVP for Cloud & Datacenter Management. I also received the PowerShell Hero 2016 award by PowerShell.0rg. And finally, I am "MCSE: Cloud Platform and Infrastructure", "MCSA: Windows Servers", "Administering & Deploying SCCM", and CheckPoint CCSA certified.