Powershell - 建立 XML 檔案



Cmdlet

New-Item Cmdlet 用於建立 xml 檔案和 Set-Content Cmdlet 用於將內容放入其中。

步驟 1

在此示例中,我們建立一個名為 test.xml 的 xml 檔案

在 PowerShell ISE 控制檯中鍵入以下命令

New-Item D:\temp\test\test.xml -ItemType File

您可以看到在 D:\temp\test 目錄中建立的 test.xml。

步驟 2

在此示例中,我們將內容新增到 test.xml 中。

在 PowerShell ISE 控制檯中鍵入以下命令

Set-Content D:\temp\test\test.xml '<title>Welcome to TutorialsPoint</title>'

步驟 3

在此示例中,我們讀取 test.xml 的內容。

Get-Content D:\temp\test\test.xml

輸出

您可以在 PowerShell 控制檯中看到以下輸出。

<title>Welcome to TutorialsPoint</title>
powershell_files_io.htm
廣告
© . All rights reserved.