Powershell - Create XML File



Cmdlet

New-Item cmdlet is used to create a xml file and Set-Content cmdlet to put content into it.

Step 1

In this example, we're creating a new xml file named test.xml

Type the following command in PowerShell ISE Console

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

You can see the test.xml created in D:\temp\test directory.

Step 2

In this example, we're adding content to test.xml.

Type the following command in PowerShell ISE Console

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

Step 3

In this example, we're reading content of test.xml.

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

Output

You can see following output in PowerShell console.

<title>Welcome to TutorialsPoint</title>
powershell_files_io.htm
Advertisements