Do you need to create an empty file in PowerShell? This is a very common requirement for PowerShell administrators. In this tutorial, we’ll explore different methods to create an empty file using PowerShell.
To create an empty file in PowerShell, you can use the New-Item cmdlet with the syntax New-Item -Path .\example.txt -ItemType File, which is the most direct method. Alternatively, you can use the Out-File cmdlet by executing Out-File -FilePath .\example.txt, or use redirection with > .\example.txt to achieve the same result. These methods provide simple and quick ways to create an empty file using PowerShell scripting.
Create an Empty File in PowerShell
Let us discuss a few methods to create an empty file in PowerShell with examples and a complete script.
Method 1: Using the New-Item Cmdlet
The New-Item cmdlet is a straightforward way to create an empty file in PowerShell. This PowerShell cmdlet can create not just files but also directories, registry keys, and other item types.
Here’s an example of how to create an empty text file named example.txt in the current directory:
New-Item -Path C:\MyFolder\example.txt -ItemType FileThis cmdlet creates a new file at the specified path. If you do not specify a path, the file will be created in the current directory.
You can see in the screenshot below that after I executed the PowerShell script using VS code, it created an empty file in the specified folder or directory.

Method 2: Using the Out-File Cmdlet
The Out-File cmdlet is typically used to send output to a file, but it can also be used to create an empty file by simply not providing any input.
For instance, to create an empty file named example.txt, you could use the following command:
Out-File -FilePath C:\MyFolder\example.txtThis command creates a new, blank text file at the specified location.
Method 3: Using Redirection Operators
In PowerShell, you can use redirection operators, similar to other shells like Bash. The > operator can be used to redirect output to a file, and if no output is specified, it results in an empty file.
Here’s how you can create an empty file with redirection in PowerShell:
> C:\MyFolder\example.txtThis will create an empty file named example.txt in the current directory.
Method 4: Using the fsutil Command
While not a PowerShell cmdlet, fsutil is a command-line utility that can be used within PowerShell to create an empty file. This is a utility native to Windows, so it may not be available in all environments.
To create an empty file using fsutil, you can run:
fsutil file createnew C:\MyFolder\example.txt 0This command creates a new file named example.txt with a size of 0 bytes, effectively creating an empty file.
Method 5: Using the .NET Framework
PowerShell can access the .NET Framework, which provides another method to create an empty file. Here’s how you can do it:
[IO.File]::WriteAllText('.\example.txt', '')This line of code uses the WriteAllText method of the File class from the System.IO namespace to create an empty file named example.txt.
Method 6: Using the New-TemporaryFile Cmdlet
If you need to create a temporary empty file, PowerShell provides the New-TemporaryFile cmdlet. This cmdlet creates an empty file with a .tmp extension in the user’s temp directory.
$tempFile = New-TemporaryFileThis command creates a temporary file and stores its file path in the $tempFile variable.
Method 7: Using echo with Redirection
Another simple method to create an empty file in PowerShell is to use the echo command with redirection. By echoing nothing into a file, you create an empty file.
echo $null > .\example.txtThis command creates an empty file named example.txt in the current directory.
Conclusion
Creating an empty file in PowerShell is easy and there are different ways to do it like by using built-in cmdlets like New-Item or Out-File, leveraging the .NET Framework, or employing traditional command-line utilities like fsutil, etc.
In this complete tutorial, I have explained how to create an empty file in PowerShell using different ways.
You may also like the following tutorials:
- How to Check if a Folder is Empty in PowerShell?
- Get Details of a File in PowerShell
- How to Count Files in a Folder Using PowerShell?
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.