If you want to know how to create a file using PowerShell, then this tutorial will be helpful for you!
How to Create a File Using PowerShell?
In PowerShell, the New-Item cmdlet is used to create single or multiple files of different types, such as text files, word documents, and others.
Use the below-given syntax of the New-Item command to create a file:
Here, -Path refers to the location where the created file will be placed
Now, let’s check out some examples of creating single and multiple files using the New-Item PowerShell command.
Creating a single file using PowerShell
To create a single file using PowerShell, use the New-Item cmdlet and specify the file path.
Here, you can see a folder named Creatingfiles, which is currently empty. The file we are going to create will be placed in this folder:
Run the below command in PowerShell to create a text file named PSfile with the .txt extension:
After executing the given command, the file is created in the E:\Powershell\CreatingFiles folder:
For verification, we will open the E:\Powershell\CreatingFiles folder, and you can see the created PSfile is saved here:
Suppose you want to create a file of any other format like a word document. To do so, specify the extension in Path as .doc with the file name:
For verification, open the E:\Powershell\CreatingFiles folder and view the document:
Want to create multiple files using PowerShell? Check out the following section!
Creating multiple files using PowerShell
In PowerShell, multiple files can be created at a time by utilizing the New-Item cmdlet:
The above-given command will create a PSTextfile.txt and a PSDocument.doc, simultaneously:
To verify if the added multiple files are created not, simply open the E:\Powershell\CreatingFiles folder and view files list:
We have provided all of the relevant information related to creating files using PowerShell.
To create a file in PowerShell, you can use the New-Item cmdlet. Its syntax is given as New-Item [-Path] <path>, where -Path refers to the location where the created file will be placed. By changing the file extension, you can create any type of file, such as a text or word document. The New-Item PowerShell command also permits you to create single and multiple files. In this tutorial, we discussed how to create a file using PowerShell with examples.