[英]How to save a Azure Function output as csv file to Blob storage
I'm running a PowerShell script in Azure function (Timer Trigger) which will fetch PowerBI workspace data from Azure and it will store to Blob storage.我在 Azure 函数(计时器触发器)中运行 PowerShell 脚本,该脚本将从 Azure 获取 PowerBI 工作区数据并将其存储到 Blob 存储。
I want the output data of the Azure function to be stored in csv format in Blob.我希望 Azure 函数的输出数据以 csv 格式存储在 Blob 中。 Currently storing as .json
当前存储为 .json
here is my query,这是我的查询,
# Input bindings are passed in via param block.
param($Timer)
# Get the current universal time in the default string format.
$currentUTCtime = (Get-Date).ToUniversalTime()
# The 'IsPastDue' property is 'true' when the current function invocation is later than scheduled.
if ($Timer.IsPastDue) {
Write-Host "PowerShell timer is running late!"
}
# Write an information log with the current time.
Write-Host "PowerShell timer trigger function ran! TIME: $currentUTCtime"
$secret="********"
$tenantId="********"
$appId="********"
$password= ConvertTo-SecureString $secret -AsPlainText -Force
$credential= New-Object System.Management.Automation.PSCredential ($appId, $password)
#Connecting to PowerBI
Connect-PowerBIServiceAccount -ServicePrincipal -Tenant $tenantId -Credential $credential
#Getting PowerBI Workspace data
$body = Get-PowerBIWorkspace -Scope Organization
#output to the blob file
Push-OutputBinding -Name outputBlob -Value $body
You can use convert from JSON to CSV to achieve this.您可以使用从 JSON 转换为 CSV来实现此目的。
# Convert your PowerBI JSON data into CSV
Get-PowerBIWorkspace -Scope Organization | ConvertTo-Json | ConvertFrom-Json | Export-Csv -Path .\PowerBIData.csv -IncludeTypeInformation
# Fetch the content of the CSV file
$body = Get-Content -Path .\PowerBIData.csv
#output to the blob file
Push-OutputBinding -Name outputBlob -Value $body
I posted an example of how to do this using the Az module commands as you are not able to modify the properties of the blob using the output binding at present and all files get saved as application/octet-stream
by default.我发布了一个如何使用 Az 模块命令执行此操作的示例,因为您目前无法使用输出绑定修改 blob 的属性,并且默认情况下所有文件都保存为
application/octet-stream
。
Output Azure Function powershell value to azure storage account 将 Azure Function powershell 值输出到 Azure 存储帐户
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.