【发布时间】:2020-01-01 01:52:36
【问题描述】:
我试图让用户通过 Azure 函数运行 powershell 脚本。该脚本应该使用用户提供的一些信息在 SharePoint 上创建一个站点。
我创建了一个 Azure Function App 来运行一些 PowerShell 脚本。当我尝试运行我的代码时,它在Connect-PnPOnline 返回了一个错误http 502
如果我删除 Connect-PnPOnline,我会收到 200 响应。所以我确信它与我脚本中的Connect-PnPOnline 有关。
我关注了@Lee_MSFT Get PowerShell Script to Run SharePoint Commands on Azure 的帖子 并且能够导入模块。
using namespace System.Net
param (
[string]$projectnumber,
[string]$projectname
)
$site = "https://xxxxx.sharepoint.com/sites/projects"
$projectsite = -join($site, "/", $projectnumber)
$projecttitle = -join($projectnumber, " ", $projectname)
Connect-PnPOnline -url $site
...
我从Connect-PnPOnline -url $site 获得了 500,从 Connect-PnPOnline -url $site -UseWebLogin 获得了 502
有人知道为什么我在使用Connect-PnPOnline 时会出现 5xx 错误吗?
非常感谢!
【问题讨论】:
-
我不认为您可以使用交互式方式在 azure 功能中进行连接。如果您的帐户启用了 MFA,您可能需要使用 AD 应用程序来执行此操作,例如
Connect-PnPOnline -AppId '<id>' -AppSecret '<secret>' -AADDomain 'contoso.onmicrosoft.com'。如果您的帐户未启用 MFA,我认为 Lee_MSFT 提供的方式可以工作。
标签: azure powershell sharepoint