Powershell - Create File



Cmdlet

New-Item cmdlet is used to create a file by passing the path using -Path as path of the file and -ItemType as File.

Example

In this example, we'll create a file in D:\Temp\Test Folder with name "Test File.txt"

Type the following command in PowerShell ISE Console

New-Item -Path 'D:\temp\Test Folder\Test File.txt' -ItemType File

Output

You will see the following output.

Directory: D:\temp

Mode                LastWriteTime     Length Name                                               
----                -------------     ------ ----                                               
-a---          4/3/2018   7:14 PM          0  Test File.txt   

You can see the same in Windows Explorer where Test File.txt is created in D:/temp/Test Folder directory.

powershell_files_folders.htm
Advertisements