簡體   English   中英

Powershell腳本創建xml文件

[英]Powershell script to create an xml file

我有一個sql命令,它將創建xml標簽,在編寫Powershell腳本時,我需要創建一個以'<'?xml version = 1.0 standalone =“ yes”?>開始的簡單xml文件。

截至目前,我有一個ps文件,例如

$inputFilePath =D:\abc.sql

$outputFilePath=D:\abc.xml

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

這只會創建一個擴展名為.xml的文件。 有人可以幫我嗎?

您可以嘗試將其傳遞到ConvertTo-Xml cmdlet。 這是3個過程對象的輸出結果。 然后,您可以將其傳送到文件:

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