简体   繁体   English

Powershell脚本创建xml文件

[英]Powershell script to create an xml file

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"?> 我有一个sql命令,它将创建xml标签,在编写Powershell脚本时,我需要创建一个以'<'?xml version = 1.0 standalone =“ yes”?>开始的简单xml文件。

as of now i have a ps file like 截至目前,我有一个ps文件,例如

$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. 这只会创建一个扩展名为.xml的文件。 Can anyone help me with it ? 有人可以帮我吗?

You can try and pipe to the ConvertTo-Xml cmdlet. 您可以尝试将其传递到ConvertTo-Xml cmdlet。 Here's how the output looks like for 3 process objects. 这是3个过程对象的输出结果。 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM