Import PowerShell Module / Package into your Azure Function App

If you have a concern about how you could use external PowerShell Modules or Packages inside of you Azure Function App written in PowerShell language then you could read this blog post where I want to show you my solution for that.

First of all you have to know that if you want to write Azure Function with PowerShell language support, then you have to use Function App with Runtime version 1.0 – so you couldn’t use latest runtime version 2.0 because there is no support for PowerShell language.

But why use PowerShell in Azure Function App? Let’s imagine scenario that we want to connect to Skype For Business Online API to which you could connect only from PowerShell.

But in that case we have to import specific PowerShell Module or Package into Function App in Azure.
You cannot simply call Import-Module SkypeOnlineConnector like on your local machine where you have previously installed SkypeOnlineConnector from that site. But you have to copy all files from that locally installed package into specific folder inside of your Function App in Azure.

So let’s take a look how you could do that.

You have to go to your Function App in Azure Portal and select Advanced tools (Kudu) from Platform features inside of it.

In Kudu you have to select Debug console / CMD from top menu.

After that you have to go to subfolder site/wwwroot/{yourFunctionName} where you have already two files inside:

Here you could create new folder with name of your PowerShell module which you want to include into your PowerShell Function App in Azure -> in my example SkypeOnlineConnector.

And you can simply drag-and-drop all files from your local powershell module location to your Azure Function App folder created above.
Locally you could find SkypeOnlineConnector in that location: C:\Program Files\Common Files\Skype for Business Online\Modules\SkypeOnlineConnector. Of course, before that you have to install it from that location.

Copy your current folder location in your Azure Function App scope from CMD window below.

After that you could simply include SkypeOnlineConnector PowerShell module in run.ps1 file like that example below:

Import-Module "D:\home\site\wwwroot\GetIPPhone\SkypeOnlineConnector\SkypeOnlineConnector.psd1"

Thats all.

Happy coding folks!

Cheers!
Gašper Rupnik

{End.}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Powered by WordPress.com.

Up ↑

%d bloggers like this: