Azure File Share as a PowerShell Module Repository

Karl WalleniusAllmänt, Azure1 Comment

PowerShell Logo

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” PS 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

(Pictures will be added).

  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”.
    Fileshare selection

    Fileshare selection

  4. Click on “+File Share”, and fill in a name and quota.
    Add FileShare

    Add FileShare

    Name and Quota

    Name and Quota

  5. Add a directory.
    Create directory

    Create 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

Log on to the machine, if it’s not your current system.

  1. Open a PowerShell command prompt.

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 repostiory.

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 Powerhell builtin Cmdlet to publish the module.

Installing a module from the repository

  1. Open a PowerShell command prompt.
  2. Issude the buildin Cmdlet that covers installation of PowerShell modules.
    Install-Module -Name ModuleName -Repository CustomModules

 

That concludes this howto.
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 sources:

Azure File Storage

One Comment on “Azure File Share as a PowerShell Module Repository”

  1. Great post Karl! Azure files are very useful and often forgotten for more complex solutions!

Leave a Reply

Your email address will not be published. Required fields are marked *