Cloud services make it easy to create and host your applications. But these benefits come with a cost. For instance underlying hardware is often shared between customers. This brings the cost down but on the other hand, you loose some control over your environment. This is necessary because otherwise other users could disrupt run of your application.
The problem
Today I encounter a problem, where I need to create C# API, which will get results from Powershell library and return these results to the user. API is hosted as Azure app service web app and the library is published on PowerShell Gallery. I am running Powershell inside my C# code using System.Management.Automation NuGet package.
First thing that comes to my mind is install the module to my runspace using command Install-Module <module name>
. This requires administrator rights and it just doesn’t work. I don’t like the idea downloading the powershell module from gallery each time anyway.
The solution
Every module published in PowerShell Gallery can also be downloaded. You can use some kind of package manager tool or do it manually. In general I like the idea of having specific tested version of the module packed with my application. After the download we ended up with package.nupkg file. But how can we integrate it into our Powershell runspace? The .nupkg filetype is nothing more than an archive. You can extract it with anything that can extract ZIP like archives. The result is shown on image bellow.