powershell - 基于 PowerShell 的 Azure 函数输出到 OneDrive
问题描述
我有一个非常简单的“hello world”类型函数。在运行.ps1
$request = Invoke-RestMethod http://ipinfo.io/json | Select -ExpandProperty ip
$out = "$env:TEMP\zhello.txt"
Set-Content -value $request -path $out
Out-File -Encoding ASCII $out
和 function.json 有这个:
{
"type": "apiHubFile",
"name": "outputFile",
"path": "output_{file}",
"connection": "onedrive_ONEDRIVE",
"direction": "out"
}
它成功运行,没有错误,但文件不在我的 OneDrive 中。还尝试使用 Azure Blob 存储作为输出。我的代码有什么问题?
解决方案
看起来您的Out-File
命令没有任何值可写入$out
文件路径。它可能正在擦除由Set-Content
.
尝试注释掉Set-Content
并$request | Out-File -Encoding ASCII $out
改用。
如果这不能解决问题,请确保您的第一行实际上是在检索数据并将其分配给$request
您认为的那样。
编辑
您也可以尝试写信$out
给主机,以确保您确切知道文件放置的位置。实施这些建议会呈现以下代码:
$request = "hello world"
$out = "$env:TEMP\zhello.txt"
Write-Host $out
$request | Out-File -Encoding ASCII $out
这会按我的预期生成文件。
如果这仍然对您不起作用,请通过尝试类似的方法确认您有权写入该文件位置"hello world 2" > "$env:TEMP\zhello.txt"
推荐阅读
- spring - Spring Boot 在 messages.properties 中使用占位符
- mysql - 使用 VBA 将 mySQL 数据库中的值提取到 Excel 中
- c# - 如何将“concat(col1+'-'+col2)”插入数据库
- javascript - 仅使内容可滚动,而其他两个组件是固定的
- c# - 移至 SharePoint 文档视图列表中的下一行
- python - 什么会导致python挂起异常?
- android - Firebase 匿名 UID 可以在 Android/iOS SDK 上自行过期吗?
- javascript - 我想使用 Xrm.WebApi.online.executeMultiple 从 Dynamics 中删除多个 CRM 记录
- flutter - 如何使用 RFlutter Alert 在启动画面上显示对话框,或者在没有 wifi 的情况下弹出对话框并退出
- django - django 默认身份验证表单显示用户名而不是电子邮件