convert Csv file into Xml on Azure data lake store using Azure Powershell runbook

Roh*_*tra 5 powershell azure-data-factory azure-data-lake azure-runbook

I want to convert CSV file into XML on Azure data lake store using Azure Powershell. I was using this code on Runbook of azure automation and it worked fine but No XML is being generated

$cred = Get-AutomationPSCredential -Name 'AutomationCred'
$subscriptionName = 'Pay-As-You-Go'
$null = Add-AzureRmAccount -Credential $cred
Select-AzureRmSubscription -SubscriptionName $subscriptionName | Out-Null 
$adla = "TestAzure"
$obj = Get-AzureRmDataLakeStoreItem -AccountName $adla -Path "/custom/logile/masters/Test/Test.csv" 
 $xmlobj = ConvertTo-Xml -InputObject $obj -As 'string' 
$xmlobj | Out-File -FilePath "/custom/logile/masters/Test/xmlOut.xml"
Run Code Online (Sandbox Code Playgroud)

直到这里的“ $ obj = Get”,此代码才能正常工作,但是我无法写入Azure数据湖。有什么方法可以使用Object在Azure数据湖中写入文件。

Kri*_*SFT 4

感谢您伸出援手!

您尝试使用 Out-File cmdlet 将 xml 文件导出到/custom/logile/masters/TestAzure 自动化执行的当前实例中不存在的路径。并且您没有将 xml 文件上传到 Data Lake Store。

要满足您的要求,您必须通过替换 Runbook 中的最后一行来使用以下命令(即最后一行是$xmlobj | Out-File -FilePath "/custom/logile/masters/Test/xmlOut.xml"

$xmlobj | Out-File -FilePath "$env:temp/xmlOut.xml"
Import-AzureRmDataLakeStoreItem -AccountName $adla -Path "$env:temp/xmlOut.xml" -Destination "/custom/logile/masters/Test/xmlOut.xml"
Run Code Online (Sandbox Code Playgroud)

我已经测试成功了。如果有兴趣,您可以查看下面的屏幕截图以进行说明。

壳牌电源运行手册

测试

数据浏览器

请注意,上面屏幕截图中我的 Runbook 的前几行与您的有所不同,因为我已向自动化帐户 RunAs 帐户授予 Data Lake 存储目标文件夹的权限。所以你可以忽略这一部分。

希望这可以帮助!!干杯!!