Azure Function PowerShell模块未从Microsoft Office. psd 1文件加载

hxzsmxv2  于 12个月前  发布在  Shell
关注(0)|答案(1)|浏览(122)

我们希望通过Azure Functions使用Microsoft Graph,但收到了错误。

[Error]   ERROR: The term 'Connect-MgGraph' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

字符串
我在requirements.psd1文件中尝试了不同的模块调用,但它似乎只是忽略了它们。

@{
    # For latest supported version, go to 'https://www.powershellgallery.com/packages/Az'. Uncomment the next line and replace the MAJOR_VERSION, e.g., 'Az' = '5.*'
    # 'Az' = '10.*'
    'Az.Accounts' = '2.5.4'
    'Microsoft.Graph.Authentication' = '2.*'

}


我的host.json文件已将managedDependency设置为true。

polhcujo

polhcujo1#

  • 在终端中手动安装Microsoft.Graph模块。
  • 在run.ps1中导入Microsoft.Graph模块:
Import-Module  -Name Microsoft.Graph

字符串
(或)
requirements.ps1中添加Microsoft.Graph模块:

@{
'Microsoft.Graph'  =  '2.2.0'
}

  • 在run.ps1中运行Connect-MgGraph以连接到Microsoft图形
Connect-MgGraph

  • 我在Azure的Http Trigger函数中运行上述命令:
    我的代码截图:
using namespace System.Net

param($Request, $TriggerMetadata)

# Importing the Microsoft.Graph Module
Import-Module  -Name Microsoft.Graph

# Connecting to the the Microsoft Graph
Connect-MgGraph

Write-Host "PowerShell HTTP trigger function processed a request."

$name = $Request.Query.Name
if (-not $name) {
    $name = $Request.Body.Name
}

$body = "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."

if ($name) {
    $body = "Hello, $name. This HTTP triggered function executed successfully."
}
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
    StatusCode = [HttpStatusCode]::OK
    Body = $body
})

*运行Azure函数时,已重定向到身份验证页面


的数据


控制台响应:


相关问题