Equivalent of Linux `touch` to create an empty file with PowerShell



As an IT administrator, you may often find yourself needing to create an empty file in Windows using PowerShell. For those familiar with Linux, this is typically done using the “touch” command. Unfortunately, no such command exists in PowerShell. However, there is a simple workaround that can be used to achieve the same result.

The first step is to create a PowerShell script that will perform the task of creating an empty file. The script should contain the following code:

$FilePath = Read-Host \Please enter the file path\
New-Item -Path $FilePath -ItemType File

This code will prompt you for the file path of the empty file that you want to create. Once you enter the file path, the script will create a new file with the specified name.

The second step is to create a batch file that will execute the PowerShell script. This can be done by creating a text file and entering the following code:

@echo off
powershell -File

Be sure to replace with the actual path to the PowerShell script that you created in the first step. Once the batch file is created, you can run it by double-clicking on it. This will execute the PowerShell script and create the empty file at the specified path.

Now that the empty file has been created, you can use it as you would any other file. For example, you can open it in a text editor, copy contents from another file into it, or delete it.

In summary, creating an empty file in Windows using PowerShell is possible. It can be done by creating a PowerShell script and a batch file that executes the script. Once the batch file is executed, the empty file will be created at the specified path. The empty file can then be used as you would any other file.

Inquire Now

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.
Find your next full or part-time role here

ScaleDesk can either help you find your next full time gig or a part time side gig where you can create extra income!

Onboard with us once
Skip HR screening and go to the final interview with with only your resume and a video interview you never have to redo
Get paid electronically every month for the hours you work
We will be your reference even if you work for us once

IT Teams: Use ScaleDesk to augment your team

Schedule Demo