从 Azure 自动化帐户 Powershell 上传数据
Upload data from Azure Automation Account Powershell
我有一些代码可以从 Azure Monitor 中提取 Kusto 查询,我需要将数据上传到 blob 存储帐户以便长期保留。
当我 运行 通过测试窗格时,我可以提取数据并将其显示在 azure 自动化屏幕中,但它不会上传到 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
基本上它使用一些存储的变量进行身份验证,然后 运行 查询 returns 下面的结果(直到那部分有效),但我想将数据上传到 Blob .
可以在以下位置找到输出示例:
https://pastebin.com/embed_iframe/fEF6NsnK
如果有更好的方法将 kusto 查询直接存储到 blob 存储,我很乐意考虑。谢谢大家:)
您的 Set-AzureStorageBlobContent
调用似乎缺少 -File
参数。您可能会在作业错误流中收到一条对此抱怨的消息。
假设您想发送存储在 $sr
变量中的数据,这样的事情应该可行(未测试):
$tempFile = New-TemporaryFile
$sr | Out-File -FilePath $tempFile.FullName
Set-AzureStorageBlobContent ... -File $tempFile.FullName
Remove-Item $tempFile
我有一些代码可以从 Azure Monitor 中提取 Kusto 查询,我需要将数据上传到 blob 存储帐户以便长期保留。
当我 运行 通过测试窗格时,我可以提取数据并将其显示在 azure 自动化屏幕中,但它不会上传到 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
基本上它使用一些存储的变量进行身份验证,然后 运行 查询 returns 下面的结果(直到那部分有效),但我想将数据上传到 Blob .
可以在以下位置找到输出示例:
https://pastebin.com/embed_iframe/fEF6NsnK
如果有更好的方法将 kusto 查询直接存储到 blob 存储,我很乐意考虑。谢谢大家:)
您的 Set-AzureStorageBlobContent
调用似乎缺少 -File
参数。您可能会在作业错误流中收到一条对此抱怨的消息。
假设您想发送存储在 $sr
变量中的数据,这样的事情应该可行(未测试):
$tempFile = New-TemporaryFile
$sr | Out-File -FilePath $tempFile.FullName
Set-AzureStorageBlobContent ... -File $tempFile.FullName
Remove-Item $tempFile