Azure File Share as a PowerShell Module Repository

Category

Tutorials

Published

May 11, 2017

There are some situations where you want your PowerShell modules and scripts to be available easily, but you don't want to make them available publicly. This is where "custom" PowerShell repositories come in and can meet your needs.

There are a couple of ways to do this. You can deploy a NuGet feed on a Web Server (this opens up for it to being open to the public later on), and you can put the PowerShell Module NuGet packages on a file share. Azure File Storage makes it possible to create a repository that you can reach from any location, but access to it is still restricted by the credentials to the Storage Account.

Let's do this!

Creating the Azure File Share

PowerShell

  1. Logon to your Azure Account and select the subscription to work with:
    Login-AzureRmAccount
    Set-AzureRmContext -SubscriptionName <subscriptionName>
  2. Create a new storage account, or use an existing.

Portal

  1. Create a Storage Account, or use an existing one.
  2. Browse to Storage Accounts in the Portal.
  3. Select the Storage Accounts and select Files in the "Overview Blade".
  4. Click on "+File Share", and fill in a name and quota.
  5. Add a directory.

That concludes the process of creating the share. Next step is to map the share on a host.

Mapping the drive on a host

  1. Log on to the machine, if it's not your current system.
  2. Open a PowerShell command prompt and enter the commands below.

Many different steps, but the end results are worth it. The final step is registering the share as a PS Repository.This next step can be performed with an ordinary SMB share on the local network as well.

Registering a PS Repository

  1. Open a PowerShell command prompt.
  2. Register a PS repository.

The above steps only needs to be done once per host, assuming you saved the credentials.Once they are done, the below commands are repeatable as soon as you open your prompt or run your builds.

Publishing a module to the repository

I will cover how to implement this in a build process on a soon-to-come blog post. Stay tuned.

  1. Open a PowerShell command prompt.
  2. Use the PowerShell builtin Cmdlet to publish the module.

Installing a module from the repository

  1. Open a PowerShell command prompt.
  2. Issue the built-in Cmdlet that covers installation of PowerShell modules:
    Install-Module -Name ModuleName -Repository CustomModules

That concludes this how-to.

Remember, after you have performed all the steps above you'll only need to do Publishing a module to the repository and Installing a module from the repository.

Additional reading: Azure File Storage

Written by

Karl Wallenius