如何在 Powershell Core Azure 函数中写入文件

How to write to a File in Powershell Core Azure Function

是否可以在 Powershell Core Azure 函数中创建和写入本地文件?

这是我 运行(使用 blob 存储触发器)的脚本的摘录。

param([byte[]] $dockerFile, $TriggerMetadata)

Write-Host "Processing updated DockerFile: $($TriggerMetadata.dockerFile)"

Write-Host "---------------------------------------------------------"
Write-Host "Create local Docker File using contents from blob storage"
New-Item -Name $TriggerMetadata.snapshotId -ItemType "file"
[io.file]::WriteAllBytes($TriggerMetadata.snapshotId, $dockerFile)
Get-Content $TriggerMetadata.snapshotId
Write-Host "---------------------------------------------------------"

使用 New-Item 抛出这个 -> ERROR: Could not find file 'D:\home\site\wwwroot\<filename>'.

并使用 [io.file]::WriteAllBytes 抛出这个 -> Exception calling "WriteAllBytes" with "2" argument(s): "Could not find file 'D:\home\site\wwwroot\<filename>'."

Azure Functions 是否有权在本地创建文件?

如前所述:使用 New-TemporaryFile command 在临时位置创建一个新文件。然后你就可以写信给它了。

$TempFile = New-TemporaryFile
[io.file]::WriteAllBytes($TempFile.FullName, $dockerFile)