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.