Azure功能:PowerShell脚本与SharePoint Online交互

Ray*_*gan 2 sharepoint-online azure-functions

我正在使用Azure Functions,特别是PowerShell脚本函数.我想知道如何使用与SharePoint Online联系的脚本.

要针对SharePoint Online运行,我通常会使用"SharePoint Online Management Shell",它是预装SharePoint Online库的PowerShell版本,以便我可以使用Get-SPOSite等方法.

如何在Azure Function PowerShell脚本中包含此库,以便我可以使用这些功能?我假设我需要在我的脚本顶部加载库,但是如何加载库?

我已将DLL上传到我的函数中并尝试使用:

[System.Reflection.Assembly]::LoadFrom('Microsoft.Online.SharePoint.Client.Tenant.dll')
Run Code Online (Sandbox Code Playgroud)

但这似乎不起作用.我认为我的问题是我不知道上传文件的绝对路径.这是我在左侧窗格中看到的内容:

在此输入图像描述

但我不知道这些文件的路径是什么.

有任何想法吗?Azure作用的文档在一分钟内令人沮丧.

Lin*_*Toh 5

Azure Functions目录的路径是

D:\home\site\wwwroot\<YourFunctionName>
Run Code Online (Sandbox Code Playgroud)

在最新的Azure Functions版本(版本0.3)中,我们支持代表您加载DLL.您需要创建一个名为modules的文件夹,并将DLL上传到该文件夹​​中.实际上,您现在可以将脚本(.psm1),二进制(.dll)和清单(.psd1)模块上载到modules文件夹中,它们将在执行脚本之前自动加载.

我们使用示例MyMathLib程序集作为参考.

假设你有一个名为功能RunSimplePowerShell,并上传了一个名为自定义库MyMathLib.dll到该文件夹,如下所示,

D:\home\site\wwwroot\RunSimplePowerShell\modules\MyMathLib.dll
Run Code Online (Sandbox Code Playgroud)

然后,您的PowerShell脚本名为run.ps1

D:\home\site\wwwroot\RunSimplePowerShell\run.ps1
Run Code Online (Sandbox Code Playgroud)

可以写成如下,

[MyMathLib.Methods]::Sum(5, 2)

$calculatorInstance= New-Object MyMathLib.Methods
$calculatorInstance.Product(5,2)
Run Code Online (Sandbox Code Playgroud)

使用Azure Functions 0.3版,您现在可以跳过该行

[Reflection.Assembly]::LoadFile("D:\home\site\wwwroot\RunSimplePowerShell\MyMathLib.dll")
Run Code Online (Sandbox Code Playgroud)