In this tutorial, I have demonstrated creating files, folders, copying them, and moving them to other locations in PowerShell. There are various File operations that can be done in PowerShell.
With powerful command-lets or cmdlets, you can do almost any file and folder operations in PowerShell than any other programming language.
Steps to Create files in PowerShell
PowerShell provides simple and easy command-let to Create files.
- Use command-let New-Item to create a file
PowerShell’s New-Item command-let is used to create an item and to set the initial content or value of the object or the item.
- Pass the folder and name of the file as -Path to the New-Item command-let
In order to a file, a folder location or path must be passed as an argument to the New-Item command-let denoting it by -Path.
- Pass -ItemType as File to specify the creation of the file
Now, you must specify the ItemType as File to let PowerShell know that you want to create a file.
- Execute the command in PowerShell Console to create the file
Finally, run the command in PowerShell Console.
Syntax
New-Item -Path <'Folder and FileName'> -ItemType File
Example
Let us create a file named test.txt in folder C:\powershell\ and to achieve it, we must build a command that looks like the below.
New-Item -Path 'C:\powershell\test.txt' -ItemType File
Run the command in the PowerShell Console.

The file test.txt has been created in the specified location.

READ: How to create XML files in PowerShell?
Steps to Create folders in PowerShell
Create folder in PowerShell using the below steps.
- Use cmdlet New-Item to create a folder
PowerShell’s New-Item command-let is used to create an item and to set the initial content or value of the object or the item. In our case, we will create a folder.
- Pass the name of the folder as -Path to the New-Item command-let
In order to create a new folder, a folder location or directory path must be passed as an argument to the New-Item command-let denoting it by -Path.
- Pass -ItemType as Directory to specify the creation of the folder
Now, you must specify the ItemType as Directory to let PowerShell know that you want to create a folder.
- Execute the command in PowerShell Console to create the folder
Finally, run the command in PowerShell Console.
Syntax
New-Item -Path <'Folder Name'> -ItemType Directory
Example
Let us create a folder named myfolder in C:\powershell\ and to achieve it, we must build a command that looks like the below.
New-Item -Path 'C:\powershell\myfolder' -ItemType Directory
Run the command in the PowerShell Console.

The folder myfolder has been created in the specified location.

Steps to Move files in PowerShell
Move files to another folder in PowerShell using the below steps.
- Use cmdlet Move-Item to move the file
PowerShell’s Move-Item command-let is used to move a file from one folder to another.
- Pass the file and directory arguments to the command-let
In order to move the file from one folder to another folder, the location of the file and destination of the folder should be passed as a arguments to the Move-Item command-let.
- Execute the command in PowerShell Console to move the file
Finally, run the command in PowerShell Console to move the file to the destination folder.
Syntax
Move-Item <'File path with Name'> <'Destination folder path'>
If the input file-path is not available in the specified directory or the path is incorrect, PowerShell throw PathNotFound exception.
Example
Let us move the file test.txt we created in our earlier post to the destination folder myfolder we created in the above step.
Move-Item C:\powershell\test.txt C:\powershell\myfolder
Run the command in the PowerShell Console.

The file text.txt has been moved to the destination folder myfolder.

Leave a Reply