带有PowerShell,存储队列触发器和OneDrive for Business的Azure功能 [英] Azure Function with PowerShell, Storage Queue trigger, and OneDrive for Business
问题描述
我正在尝试创建一个Azure函数,该函数通过Storage Queue触发器执行PowerShell.出于测试目的,我希望此功能可以处理OneDrive for Business帐户中的文件.要将文件从aapdftoimage/ThreePages.pdf
复制到aapdftoimage/output_ThreePages.pdf
.
I'm trying to create an Azure Function that executes PowerShell with a Storage Queue trigger. For testing purposes, I want this function to manipulate a file in my OneDrive for Business account. To copy the file at aapdftoimage/ThreePages.pdf
to aapdftoimage/output_ThreePages.pdf
.
将OneDrive for Business集成为输入时,只要队列中的新消息触发该功能,我都会收到错误消息.如果我断开OneDrive作为输入的连接,则不会出现任何错误,并且$triggerInput
包含该消息.
When OneDrive for Business is integrated as an Input, I get errors any time the function is triggered by a new message in the queue. If I disconnect OneDrive as input I don't get any errors and $triggerInput
contains the message.
错误是:
2017-05-25T22:24:38.484 Function started (Id=a0c37fdf-ed3c-473c-9c79-236d63531e7e)
2017-05-25T22:24:38.499 Function completed (Failure, Id=a0c37fdf-ed3c-473c-9c79-236d63531e7e, Duration=1ms)
2017-05-25T22:24:38.562 Exception while executing function: Functions.QueueTriggerPowerShell1. Microsoft.Azure.WebJobs.Host: No value for named parameter 'file'.
这是我的PowerShell:
Here's my PowerShell:
$inData = Get-Content $triggerInput
$inFile = Get-Content $inputFile
Write-Output "PowerShell script processed queue message '$inData'"
Write-Output "inFile: $inFile"
这是function.json:
Here's function.json:
{
"bindings": [
{
"name": "triggerInput",
"type": "queueTrigger",
"direction": "in",
"queueName": "samples-powershell-pdftoimage",
"connection": "<storageaccount>_STORAGE"
},
{
"type": "apiHubFile",
"name": "inputFile",
"path": "aapdftoimage/{file}",
"connection": "onedriveforbusiness1_ONEDRIVEFORBUSINESS",
"direction": "in"
}
],
"disabled": false
}
在撰写本文时,我认为部分困惑在于OneDrive for Business的输入和输出(在测试中未连接)集成.
As I'm writing this, I think part of my confusion is over the Input and Output (not connected in my test) integrations of OneDrive for Business.
我知道$triggerInput
是什么.这是消息的内容.但是什么是$inputFile
? {file}
是从哪里来的?
I know what $triggerInput
is. It's the content of the message. But what is $inputFile
? And where does {file}
come from?
我想也许我会执行以下操作,但是它也不起作用(相同的错误):
I thought maybe I would do the following but it too doesn't work (same errors):
$file = Get-Content $triggerInput
我认为这可能将$inputFile
定义为"aapdftoimage/$ file",但它没有任何作用.
I thought this might define $inputFile
as "aapdftoimage/$file" but it does nothing of the sort.
不用说,我正处于停滞状态.谁能给我一些指导并理顺我?
Needless to say, I'm at a standstill. Can anyone give me some guidance and straighten me out?
推荐答案
@Henry Hamid Safi是正确的.使用C#,您可以利用Binder对象动态命名文件.
@Henry Hamid Safi is correct. Using C#, you can leverage the Binder object to dynamically name the file.
在您的用例中,动态提供文件名的唯一方法是在触发器有效负载中将其作为JSON对象传递.这是对我有用的示例设置.
In your use-case, the only way to dynamically provide the name of the file is to pass it as a JSON object in your trigger payload. Here is a sample setup that worked for me.
function.json:
{
"bindings": [
{
"name": "triggerInput",
"type": "queueTrigger",
"direction": "in",
"queueName": "samples-powershell",
"connection": "AzureWebJobsStorage"
},
{
"type": "apiHubFile",
"name": "inputFile",
"path": "aapdftoimage/{file}",
"connection": "onedriveforbusiness_ONEDRIVEFORBUSINESS",
"direction": "in"
},
{
"type": "apiHubFile",
"name": "outputFile",
"path": "aapdftoimage/output_{file}",
"connection": "onedriveforbusiness_ONEDRIVEFORBUSINESS",
"direction": "out"
}
],
"disabled": false
}
run.ps1:
$in = Get-Content $triggerInput
Write-Output "PowerShell script processed queue message '$in'"
Copy-Item $inputFile $outputFile
请求正文(如果在Portal中使用测试"窗格)或队列触发器有效负载:
{
"file":"ThreePages.pdf"
}
日志条目:
2017-05-26T22:27:53.984 Function started (Id=032c4469-8378-44ce-af9e-5a941afb0d82)
2017-05-26T22:27:54.875 PowerShell script processed queue message '{ "file":"ThreePages.pdf" }'
2017-05-26T22:27:54.891 Function completed (Success, Id=032c4469-8378-44ce-af9e-5a941afb0d82, Duration=899ms)
OneDrive文件夹屏幕截图:
这篇关于带有PowerShell,存储队列触发器和OneDrive for Business的Azure功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!