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 'xyz'
$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"
This code is working fine till "$obj= Get" here, but I am not able to write into Azure data lake. Is there any way that I can use Object to write the file in Azure data lake.
How to convert a CSV to a XML file? Choose the CSV file that you want to convert. Select XML as the the format you want to convert your CSV file to. Click "Convert" to convert your CSV file.
File -> Import -> Text File.Browse for the . csv file and press OK. You will obtain the Import criteria dialog that allows you to choose the field delimiter from the CSV and customize the form of the destination XML file(Change labels).
Thanks for reaching out!
You were trying to export the xml file using Out-File cmdlet to an nonexistent path /custom/logile/masters/Test
in current instance of the Azure Automation execution. And you were not uploading the xml file to a Data Lake Store.
To accomplish your requirement you would have to use the below commands by replacing last line in your runbook (i.e., last line is $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"
I have tested it successfully. If interested you may check below screenshots for illustration.
Note that the first few lines of my runbook in the above screenshot are a bit different from yours because I have given Automation Account RunAs account the permission to Data Lake store destination folder. So you may ignore this part.
Hope this helps!! Cheers!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With