1

I have a sql command which will create xml tags , on writing a powershell script i need to create a simple xml file which starts with '<'?xml version=1.0 standalone="yes"?>

as of now i have a ps file like

$inputFilePath =D:\abc.sql

$outputFilePath=D:\abc.xml

invoke-sqlcmd -inputFile $inputFilePath | Format-Table -hide -Wrap -AutoSize  | Out-File -filePath $outputFilePath 

This just creates a file with .xml extention. Can anyone help me with it ?

1 Answer 1

3

You can try and pipe to the ConvertTo-Xml cmdlet. Here's how the output looks like for 3 process objects. You can then pipe it out to a file :

PS> gps | select name,id -first 3 | ConvertTo-Xml -As String -NoTypeInformation


<?xml version="1.0"?>
<Objects>
  <Object>
    <Property Name="Name">AppleMobileDeviceService</Property>
    <Property Name="Id">1568</Property>
  </Object>
  <Object>
    <Property Name="Name">audiodg</Property>
    <Property Name="Id">5140</Property>
  </Object>
  <Object>
    <Property Name="Name">Babylon</Property>
    <Property Name="Id">4908</Property>
  </Object>
</Objects>
Sign up to request clarification or add additional context in comments.

Comments

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.