【问题标题】:Upload data from Azure Automation Account Powershell从 Azure 自动化帐户 Powershell 上传数据
【发布时间】:2020-01-18 03:13:50
【问题描述】:

我有一些代码可以从 Azure Monitor 中提取 Kusto 查询,我需要将数据上传到 Blob 存储帐户以进行长期保留。

当我通过测试窗格运行时,我可以提取数据并将其显示在天蓝色的自动化屏幕中,但它不会上传到 blob。

我认为错误就在这里

    $SearchResult 

    $StorageAccountName = Get-AutomationVariable -Name "AccessKey"
    $StorageAccountKey = Get-AutomationVariable -Name "StorageAccName"

    foreach ($sr in $SearchResult){        
$ctx = New-AzureStorageContext -StorageAccountName $StorageAccountName `
         -StorageAccountKey $StorageAccountKey    
$ContainerName = "Data"    
New-AzureStorageContainer -Name $ContainerName -Context $ctx -Permission Blob

$BlobName = "$sr"
Set-AzureStorageBlobContent -Container $ContainerName -Blob $BlobName `
        -Context $ctx

完整的脚本如下

https://pastebin.com/embed_iframe/RyLJZVKW

基本上,它使用一些存储的变量进行身份验证,然后运行返回以下结果的查询(直到该部分有效),但随后我想将数据上传到 Blob。

输出示例可以在以下位置找到:

https://pastebin.com/embed_iframe/fEF6NsnK

如果有更好的方法将 kusto 查询直接存储到 blob 存储中,我很乐意考虑 .. 谢谢大家 :)

【问题讨论】:

    标签: azure powershell azure-automation azure-data-explorer


    【解决方案1】:

    您的Set-AzureStorageBlobContent 调用似乎缺少-File 参数。您可能会在作业错误流中收到一条抱怨此问题的消息。

    假设您要发送存储在$sr 变量中的数据,这样的事情应该可以工作(未经测试):

    $tempFile = New-TemporaryFile
    $sr | Out-File -FilePath $tempFile.FullName
    Set-AzureStorageBlobContent ... -File $tempFile.FullName
    Remove-Item $tempFile
    

    【讨论】:

    • 您好,谢谢,我不知道如何捕获每个文件并在它通过循环时发送到 azure,如何将每个文件发送到 blob 存储?
    • 太棒了,我会试一试:)
    • 嗨,我收到此错误Set-AzureStorageBlobContent -Container $ContainerName -File $temp ... 我已将代码修改为pastebin.com/embed_iframe/4TXEqsKE 我认为 $seachResult 是一个数组,也许?
    猜你喜欢
    • 2020-12-09
    • 2021-09-19
    • 2020-08-29
    • 2021-05-25
    • 2020-04-21
    • 2020-07-24
    • 2021-06-21
    • 1970-01-01
    • 2021-06-07
    相关资源
    最近更新 更多