0

I need some advice to convert the XEL file to XML. I am executing a PowerShell script in Azure Automation runbook in Azure portal to store the XEL file from BLOB storage to my local machine, converting it and then uploading the final XML it to another blob storage.

The issue is that since the PowerShell script runs in the Azure portal it is not able to find the local path where it can store the XEL files. There are no errors as such but the code below doesn't seem to run. I have tried several ways to accomplish this right from using in memory stream but it did not help. Below is the code snippet. Can anyone help ?

    try {
    $eventReader = [Microsoft.SqlServer.XEvent.Linq.QueryableXEventData]::new($LocalFilePath)
    $xmlWriter = [System.Xml.XmlWriter]::Create($OutputFilePath)
    
    $xmlWriter.WriteStartDocument()
    $xmlWriter.WriteStartElement("ExtendedEvents")

    foreach ($event in $eventReader) {
        $xmlWriter.WriteStartElement("Event")
        foreach ($field in $event.Fields) {
            $xmlWriter.WriteElementString($field.Name, $field.Value.ToString())
        }
        $xmlWriter.WriteEndElement() # Event
    }

    $xmlWriter.WriteEndElement() # ExtendedEvents
    $xmlWriter.WriteEndDocument()
    $xmlWriter.Close()

You can see here the $localpath has been defined earlier as a temp folder in my LocalMachine and same with the $OutputFilePath but it seems like these local paths are not accessible by PowerShell running in the cloud (Azure automation runbook). Can anyone please guide me as to what needs to be done here so that the file can be downloaded and converted.

3
  • What if you SELECT the XEL from Azure SQL Database and then convert to XML there? stackoverflow.com/questions/76826825/… could that be a solution fo you? Commented Jan 6 at 9:03
  • Because it seems to me that you have 2 problems here: PowerShell doesn't convert to XML and doesn't save to $OutputFilePath. Is that because the $OutputFilePath is on-prem and not on the cloud? Commented Jan 6 at 9:04
  • I would discourage converting data from an XEL file into XML. Strings in XEL files can contain null characters which are unrepresentable in most XML serialization schemes. Commented Mar 11 at 20:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.