在Azure功能中安装Powershell模块

在Azure功能中安装Powershell模块

本文介绍了在Azure功能中安装Powershell模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Azure Function 2.0与Powershell一起使用,并在安装Powershell模块时遇到以下错误.

I'm using Azure Function 2.0 with Powershell and getting below error while installing Powershell modules.

是否有任何方法可以消除此错误.通常,我们不需要管理员权限即可安装NuGet/Dependency.

Is there any way to get rid of this error. In general, we don't need admin rights to install NuGet/dependency.

我还尝试了另一种方法将所有Powershell模块放在Modules文件夹下

I also tried with another way to put all Powershell modules under Modules folder

功能仍然无法找到Cosmos DB模块

Still, function is not able to find Cosmos DB modules

推荐答案

不能像以前在本地计算机上那样简单地调用 Import-Mod Az.Profile 从该站点安装了 Az.Profile .但是您必须将所有文件从该本地安装的软件包复制到Azure中Function App内的特定文件夹中.

You cannot simply call Import-Module Az.Profile like on your local machine where you have previously installed Az.Profile 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.

1.在本地安装 Az.Profile 并转到其文件夹以获取其中的所有内容.

1.Install Az.Profile in local and go to its folder to get all the content in it.

2.转到功能KUDU.单击CMD>站点> wwwroot> yourFunctionName,然后创建一个名为 modules 的目录.

2.Go to your function KUDU. Click CMD>site>wwwroot>yourFunctionName then create a directory called modules.

3.只需将所有文件从本地Powershell模块位置拖放到Azure Function App文件夹中,即可在上方创建(模块).

3.Simply drag-and-drop all files from your local powershell module location to your Azure Function App folder create above(modules).

4.将 Az.Profile PowerShell模块包含在 run.ps1 文件中,如下例所示:

4.Include Az.Profile PowerShell module in run.ps1 file like that example below:

Import-Module "D:\home\site\wwwroot\HttpTrigger1\modules\Az.Profile.psd1"

5.按上述步骤安装 Az.Resources CosmosDB 模块.

5.Install Az.Resources and CosmosDB module as above steps.

6.运行 Get-CosmosDbOffer -Context $ cosmosDbContext ,您将获得以下快照.

6.Run Get-CosmosDbOffer -Context $cosmosDbContext and you will get the following snapshot.

有关更多详细信息,您可以参考此教程和此一个.

For more details, you could refer to this tutorial and this one.

这篇关于在Azure功能中安装Powershell模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 18:52