【发布时间】:2019-01-25 08:41:03
【问题描述】:
只是为了管理期望,我是 PowerShell 和 Azure Functions 的新手。
由于 Azure Functions 2.x 不再支持 PowerShell,因此我尝试运行需要来自 C# 的 SPO 模块的 PowerShell 脚本(以下代码)我在运行 Azure Function App 时遇到问题,因为 PowerShell 脚本需要 SPO 模块。任何知道如何在 C# PowerShell 实例中安装所需模块的人,比如 Runspace 或类似的东西?我什至在正确的轨道上?任何 cmets 都受到高度赞赏。谢谢大家。
示例代码:
[FunctionName("TestFunction")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, TraceWriter log)
{
using (PowerShell PowerShellInstance = PowerShell.Create())
{
var script = @"
Install-Module Microsoft.Online.SharePoint.PowerShell
Install-Module SharePointPnPPowerShellOnline
$url = '<SharePoint Url>'
$ListName = '<List Name>'
Connect-PnPOnline -Url $url -UseWebLogin
$Fields = Get-PnPField -List $ListName
$Items= Get-PnPListItem -List $ListName -PageSize 5000
$RowCtr = 1;
foreach($item in $items.FieldValues)
{
#do something
$RowCtr++;
}
";
PowerShellInstance.AddScript(script);
var results = PowerShellInstance.Invoke();
//some other codes
}
}
【问题讨论】:
标签: c# powershell azure-functions azure-functions-runtime