Azure Automation 无法将文件传输到存储帐户。

huangapple go评论65阅读模式
英文:

Azure Automation unable to transfer files to storage account

问题

我试图让Azure Automation账户将一个.CSV文件导出到一个存储账户,但是我在这方面遇到了很大的麻烦。正如大多数文档所说要使用AzureRM,而Azure RM正在被弃用。

以下是我尝试传输.CSV文件的方式:

$SecureAppSecret = ConvertTo-SecureString -String $AppSecret -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential($AppId, $SecureAppSecret)
Connect-AzAccount -ServicePrincipal -TenantId $TenantId -Credential $Credential
[String]$StorageAccountKey = Get-AzStorageAccountKey -ResourceGroupName $ResourceGroupID -Name $StorageAccountName

$azure_StorageContextSplat = @{
    StorageAccountName = $StorageAccountName
    StorageAccountKey = $StorageAccountKey
}
$storageContext = New-AzStorageContext @azure_StorageContextSplat

$Report | Export-CSV -Path "~\File.csv"

$azure_FileToUploadSplat = @{
    Context = $storageContext
    File = "~\File.csv"
    Container = $StorageContainer
    Force = $true
}

Set-AzStorageBlobContent @azure_FileToUploadSplat

$AppSecret、$AppId、$TenantId、$ResourceGroupID、$StorageAccountName和$storageContext都在脚本的前面以明文形式提供(我知道这不安全,但我想让它工作,然后再加固)。

在Azure Automation测试窗格中运行后,我收到以下两个错误:

输入不是有效的Base-64字符串,因为它包含一个非Base 64字符,超过两个填充字符,或在填充字符中有一个非法字符。

无法获取存储上下文。请传递一个存储上下文或设置当前存储上下文。

我相信第一个错误是指StorageAccountKey,但在这一点上我不确定。任何帮助都将不胜感激。谢谢。

英文:

I am attempting to have an Azure Automation account export a .CSV to a Storage Account however I am running into a significant amount of trouble doing so. As most documentation says to use AzureRM and Azure RM is being depreciated.

Here is how I'm attempting to transfer the .CSV

$SecureAppSecret = ConvertTo-SecureString -String $AppSecret -AsPlainText -Force
$Credential = New-Object -TypeName System.Management.Automation.PSCredential($AppId, $SecureAppSecret)
Connect-AzAccount -ServicePrincipal -TenantId $TenantId -Credential $Credential
[String]$StorageAccountKey = Get-AzStorageAccountKey -ResourceGroupName $ResourceGroupID -Name $StorageAccountName

$azure_StorageContextSplat = @{
StorageAccountName = $StorageAccountName
StorageAccountKey = $StorageAccountKey
}
$storageContext = New-AzStorageContext @azure_StorageContextSplat

$Report | Export-CSV -Path "~\File.csv"

$azure_FileToUploadSplat = @{
Context = $storageContext
File = "~\File.csv"
Container = $StorageContainer
Force = $true
}

Set-AzStorageBlobContent @azure_FileToUploadSplat

$AppSecret, $AppId, $TenantId, $ResourceGroupID, $StorageAccountName, and $storageContext are all provided earlier in the script as plaintext (I know it's not secure but I want it to work then I can make it secure)

After running this in the Azure Automation test pane I get the following 2 errors:

The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. 


Could not get the storage context.  Please pass in a storage context or set the current storage context.

I believe the first one refers to StorageAccountKey but at this point I don't know. Any help at all would be appreciated.
Thank you.

答案1

得分: 1

以下是翻译好的部分:

"Simple way to transfer file is the below process and take it as an alternative as it is little less secure:" => "传输文件的简单方法如下所示,并将其视为一种替代方法,因为它略显不安全:"

"I have reproduced in my environment and the below script worked for me and I followed Microsoft-Document:" => "我在我的环境中复制了以下脚本,并且它对我起作用,我遵循了Microsoft文档:"

"Import-Module -Name Azure.Storage" => "导入模块 -Name Azure.Storage"

"$storageAccName = "rithwikstorage"" => "$storageAccName = "rithwikstorage""

"$storageAccKey = "ohNJHBheHNb/gSSBWXUxt3dxrw+AStXNnJyQ=="" => "$storageAccKey = "ohNJHBheHNb/gSSBWXUxt3dxrw+AStXNnJyQ==""

"$context = New-AzStorageContext -StorageAccountName $storageAccName -StorageAccountKey $storageAccKey" => "$context = New-AzStorageContext -StorageAccountName $storageAccName -StorageAccountKey $storageAccKey"

"$conName = "name of the conatiner"" => "$conName = "name of the conatiner""

"$Report =Get-AzResource | Export-CSV -Path "~\File.csv"" => "$Report =Get-AzResource | Export-CSV -Path "~\File.csv""

"Set-AzStorageBlobContent -Context $context -Container $conName -File "~\File.csv"" => "Set-AzStorageBlobContent -Context $context -Container $conName -File "~\File.csv""

"Azure Automation 无法将文件传输到存储帐户。" => "Azure Automation 无法将文件传输到存储帐户。"

"Output:" => "输出:"

"Azure Automation 无法将文件传输到存储帐户。" => "Azure Automation 无法将文件传输到存储帐户。"

"Then in Storage Account:" => "然后在存储帐户中:"

"Azure Automation 无法将文件传输到存储帐户。" => "Azure Automation 无法将文件传输到存储帐户。"

"Here I have given storage account key , name and container name directly and I got desired output, try to follow the same to get desired output as I have got." => "在这里,我直接提供了存储帐户密钥、名称和容器名称,我获得了所需的输出,请尝试按照相同的方式获取所需的输出。"

英文:

Simple way to transfer file is the below process and take it as an alternative as it is little less secure:

I have reproduced in my environment and the below script worked for me and I followed Microsoft-Document:

Import-Module -Name Azure.Storage

$storageAccName = "rithwikstorage"
$storageAccKey = "ohNJHBheHNb/gSSBWXUxt3dxrw+AStXNnJyQ=="

$context = New-AzStorageContext -StorageAccountName $storageAccName -StorageAccountKey $storageAccKey

$conName = "name of the conatiner"
$Report =Get-AzResource | Export-CSV -Path "~\File.csv"

Set-AzStorageBlobContent -Context $context  -Container $conName -File "~\File.csv"

Azure Automation 无法将文件传输到存储帐户。

Output:
Azure Automation 无法将文件传输到存储帐户。

Then in Storage Account:

Azure Automation 无法将文件传输到存储帐户。

Here I have given storage account key , name and container name directly and I got desired output, try to follow the same to get desired output as I have got.

huangapple
  • 本文由 发表于 2023年2月23日 22:19:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/75546061.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定