azure - 如何在 Azure Function App 上运行 PnP 脚本
问题描述
我试图让用户通过 Azure 函数运行 powershell 脚本。该脚本应该使用用户提供的一些信息在 SharePoint 上创建一个站点。
我创建了一个 Azure Function App 来运行一些 PowerShell 脚本。当我尝试运行我的代码时,它http 502
在Connect-PnPOnline
If I remove处返回错误Connect-PnPOnline
,我得到 200 响应。所以我确信它与Connect-PnPOnline
我的脚本有关。
我关注了@Lee_MSFT 的帖子, 获取 PowerShell 脚本以在 Azure 上运行 SharePoint 命令 并能够导入模块。
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
...
我得到了 500Connect-PnPOnline -url $site
和 502Connect-PnPOnline -url $site -UseWebLogin
有人知道为什么我在使用时会出现 5xx 错误Connect-PnPOnline
吗?非常感谢!
解决方案
确保已为 Azure Function 上传 PnP PowerShell 模块,然后使用下面的 PowerShell 连接 SharePoint。
$siteURL = "https://tenant.sharepoint.com/sites/projects"
$userId = "abc@tenant.onmicrosoft.com"
$plainText= "*****"
$pwd = ConvertTo-SecureString $plainText -AsPlainText -Force
$creds = New-Object System.Management.Automation.PSCredential($userId,$pwd)
Connect-PnPOnline -Url $siteURL -Credentials $creds
或者使用这个:
Connect-PnPOnline -AppId $env:SPO_AppId -AppSecret $env:SPO_AppSecret -Url "https://tenant.sharepoint.com/sites/projects"
SPO_AppId - 将值设置为您在第一步中在租户上创建应用程序时复制的客户端 ID。
SPO_AppSecret - 将值设置为您在第一步中在租户上创建应用程序时复制的客户端密码。
我建议您检查下面文章中的步骤。
推荐阅读
- dynamics-crm - 无法为 MS Dynamics CRM 2011 中的团队实体注册预删除验证插件步骤
- sql - 在 postgres 中使用侧面插入或更新查询中的变量
- azure-devops - Azure 是否提供用于将测试自动化结果发布到 Azure Devops Testlabs 的 Rest API?
- azure - linux机器上的慢rm -rf
- sorting - Redis:排序命令返回的字符串上升顺序错误
- linux - TCP_NODELAY 参数对 MSS 和 CPU 利用率的影响
- ios - Quasar 文件选择器不会在 ios 中上传图像
- maven - 带有 org.springdoc 的 Swagger-UI (v3) 确实显示和解释枚举不正确
- eclipse - 无法打开包含 2000 万行的文本文件
- google-sheets - 如何从一个单元格为 SUMIF 应用多个条件 | 谷歌表格