简体   繁体   English

如何将 Azure 函数输出作为 csv 文件保存到 Blob 存储

[英]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来实现此目的。

Workaround follows解决方法如下

# 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.

相关问题 如何使用 azure ZC1C425Z574E68385D1CAB1 编辑 azure blob 存储中的 *.csv 文件 - How to edit a *.csv file in the azure blob storage with an azure function? 通过Azure函数导出cosmosDB并将文件保存在Blob存储中 - Export cosmosDB by an azure function and save the file in a blob storage 在 azure blob 存储中重命名 spark 输出 csv - Renaming spark output csv in azure blob storage Azure function C#:写入 Azure 上的块 blob(csv 文件)存储帐户创建了两个版本的 blob - Azure function C#: Writing to Block blob (csv file) on Azure Storage Account creates two versions of the blob 如何检查上传到 azure blob 存储中的 csv 文件中的记录计数? - How to check record count in a csv file uploaded in azure blob storage? 如何在 Azure(.Net) 中导入 csv 文件(已上传到 blob 存储中) - How to import csv file( already uploaded in blob storage) in Azure(.Net) 如何在 Azure Blob 存储中覆盖后命名 csv 文件 - How to name a csv file after overwriting in Azure Blob Storage 将 csv 文件写入 azure blob 存储 - Write a csv file into azure blob storage 将CSV文件上传到Azure BLOB存储 - Upload csv file to Azure BLOB Storage 将 excel 文件 stream 保存到 azure blob 存储 - save excel file stream to azure blob storage
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM