---
title: "Utilizing PowerShell and Windows Command Prompt to Create File"
description: "If you need to use the Windows command prompt to create file, look no further. Learn how to create text files with the command prompt and PowerShell!"
canonical: "https://adamtheautomator.com/command-prompt-to-create-file/"
---

# Utilizing PowerShell and Windows Command Prompt to Create File

> If you need to use the Windows command prompt to create file, look no further. Learn how to create text files with the command prompt and PowerShell!

Source: https://adamtheautomator.com/command-prompt-to-create-file/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![Utilizing PowerShell and Windows Command Prompt to Create File](https://adamtheautomator.com/wp-content/uploads/2021/05/How-to-Create-a-Text-File-on-the-Command-Prompt-in-Windows.jpg)

# Utilizing PowerShell and Windows Command Prompt to Create File

[![](https://secure.gravatar.com/avatar/75fa5f572fb085a46bfff406309882e0848db4770557901e8de897b3f7d05a7a?s=192&d=mm&r=g)Nick Rimmer](https://adamtheautomator.com/author/nick/)1 June 20215 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[Command Line](/tag/command-line/)[File Management](/tag/file-management/)

Table of Contents

*   [Prerequisites](#h-prerequisites)
*   [Using Windows Command Prompt to Create File](#h-creating-a-file-with-the-windows-command-prompt)
*   [Using the ECHO Command](#h-using-the-echo-command)
*   [Using the COPY CON Command](#h-using-the-copy-con-command)
*   [Using the FSUTIL Command](#h-using-the-fsutil-command)
*   [Creating a File with PowerShell](#h-creating-a-file-with-powershell)
*   [Using the New-Item Cmdlet](#h-using-the-new-item-cmdlet)
*   [Using the Set-Content and Add-Content Cmdlets](#h-using-the-set-content-and-add-content-cmdlets)
*   [Using the Out-File Cmdlet](#h-using-the-out-file-cmdlet)
*   [Conclusion](#h-conclusion)

To create a file in Windows, right-click on your desktop or in File Explorer and click on **New**. Is this post going to be the shortest post ever? Nope. Because using the GUI sometimes won’t work, you can use the command prompt to create a file. In this tutorial, you will learn just about every way possible to use PowerShell and Windows command prompt to create file on the command line.

Let’s get started!

## Prerequisites

If you’d like to follow along with the steps in this tutorial, be sure you have the following ahead of time:

*   A Windows PC – All demos in this tutorial will use Windows 10, but Windows 7+ will work also.
*   PowerShell 3.0+ – All demos in this tutorial will use PowerShell v7.1.3.

## Using Windows Command Prompt to Create File

You have two command-line options in Windows; the command prompt (_cmd.exe_) or PowerShell. Let’s first cover how to use the Windows command prompt to create a file that is blank.

To get started, open the Windows command prompt by clicking on the Start button, typing _cmd.exe,_ and hitting Enter. The Windows command prompt should come up, and you’re ready to go.

### Using the ECHO Command

Let’s start this tutorial by first covering the [echo](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/echo) command. The echo command is a command-line utility that allows you to display messages in a command prompt. In Windows, if you can send something to the command console, you can also redirect that output to a file!

In the Windows **Command Prompt** window:

1\. Run the echo command as shown below. This command _echoes_ the text provided (`This is a sample text file`) to the command console. But, since the command is using the [redirection operator](https://ss64.com/nt/syntax-redirection.html) (`>`), this operator tells Windows to instead create a file with the text (`sample.txt`).

When you’ve created the file, run the `dir` command to list all files in the [current working directory](https://www.computerhope.com/jargon/c/currentd.htm)

```bash
echo This is a sample text file > sample.txt
 dir
```

You can see below that Windows creates the _sample.txt_ file in the current working directory.

![Output of redirecting text to sample.txt](https://adamtheautomator.com/wp-content/uploads/2021/05/Untitled-2021-05-31T094339.120.png)

Output of redirecting text to sample.txt

2\. To confirm the file contains the expected “_This is a sample text file”_ text, execute the [`type`](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/type) command followed by the file name. The `type` command reads the file and returns the text inside.

You can see below that _sample.txt_ does, indeed, contain the expected text.

```bash
type sample.txt
```

![Output of type, showing the contents of sample.txt](https://adamtheautomator.com/wp-content/uploads/2021/05/Untitled-2021-05-31T094544.746.png)

Output of type, showing the contents of sample.txt

### Using the COPY CON Command

If the `echo` command doesn’t fit your taste, you can always use the `copy` command using the `con` argument. Instead of copying files, the `con` argument tells the `copy` command to copy output to the console.

> _The `con` argument is actually a device, not a command._

To create a file using `copy con`:

1\. Run `copy con` followed by a file name. This command won’t immediately create the file. You’ll be presented with a flashing cursor.

```bash
copy con sample.txt
```

2\. Once you see that flashing cursor type in some text you’d like to include in the file and press Enter.

```bash
This is a sample of what you can do
```

When you’re done, press Ctrl-Z and press Enter to exit the interactive prompt. Pressing Ctrl-Z will also add an [end-of-file marker](https://www.computerhope.com/jargon/e/eof.htm) to tell Windows to close the open [file handle](https://www.computerhope.com/jargon/f/filehand.htm).

You can see below pressing Ctrl-Z will display `^Z`, and Windows will tell you it’s “copied” one file. This file will be the file you specified and will contain the text you just typed.

![Ctrl-Z to create an end of file marker](https://adamtheautomator.com/wp-content/uploads/2021/05/Untitled-2021-05-31T094823.444.png)

Ctrl-Z to create an end of file marker

### Using the FSUTIL Command

You can also use Windows command prompt to create file by introducing [fsutil](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/fsutil)! Fsutil is a file system management tool built into Windows.

To use fsutil on the command prompt to create a new file:

1\. Close the command prompt if you still have it open and open it up again, but this time as an administrator. Unfortunately, the fsutil utility requires it.

![Opening Command Prompt as Admin](https://adamtheautomator.com/wp-content/uploads/2021/05/Untitled-2021-05-31T094913.339.png)

Opening Command Prompt as Admin

2\. Now, invoke the [`file` function](https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/fsutil-file) of fsutil to create a new file using the `createnew` argument followed by the file name to create (`sample.txt`) and the size in bytes you’d like the file to be (`1000`).

The below command will create a file called _sample.txt_ in the current working directory that’s 1KB in size.

```bash
fsutil file createnew sample.txt 1000
```

3\. Type `dir` again to list all files in the current working directory and you should see a 1,000-byte file now exists.

![Create a fixed size file](https://adamtheautomator.com/wp-content/uploads/2021/05/Untitled-2021-05-31T095049.026.png)

Create a fixed size file

> _Since the fsutil utility can create blank files of a certain size, the utility is great for creating dummy files for network performance testing!_

## Creating a File with PowerShell

It’s now time to use a more modern approach of using a Windows command prompt to create file; with PowerShell! PowerShell has a few different ways to create a file so let’s cover them all.

So, open your Windows PowerShell or PowerShell console and let’s get started!

### Using the `New-Item` Cmdlet

One of the easiest ways to create a file in Windows with [PowerShell](https://adamtheautomator.com/powershell-check-if-file-exists/) is to use the [`New-Item` cmdlet](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-item?view=powershell-7.1) This cmdlet creates new items (a file in this case).

> _The `New-Item` cmdlet can also create Windows registry keys or folders._

Related:[How to use PowerShell to Check if a File Exists (Examples)](https://adamtheautomator.com/powershell-check-if-file-exists/)

1\. Run the `New-Item` cmdlet specifying the directory to create the file in (`Path`), the `Name` of the file, the type of item (`ItemType`), and finally, the text to include in the file (`Value`).

The below command will create a file called _sample.txt_ in the current working directory (`.`) with the text `This is a text string` inside the file.

```powershell
New-Item -Path . -Name "sample.txt" -ItemType "file" -Value "This is a text string"
```

![Creating a new file with the PowerShell New-Item cmdlet ](https://adamtheautomator.com/wp-content/uploads/2021/05/Untitled-2021-05-31T095534.272.png)

Creating a new file with the PowerShell New-Item cmdlet

> _You can also use `New-Item` to create a directory by using the `Directory` argument for the `ItemType` parameter._

2\. Now, take a look at the file just created using the [`Get-Content` cmdlet](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-content?view=powershell-7.1) to tell PowerShell to read the file and display its contents.

![Displaying file contents with the PowerShell Get-Content cmdlet](https://adamtheautomator.com/wp-content/uploads/2021/05/Untitled-2021-05-31T095639.229.png)

Displaying file contents with the PowerShell Get-Content cmdlet

### Using the `Set-Content` and `Add-Content` Cmdlets

Next, let’s check out the [`Set-Content`](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/set-content?view=powershell-7.1) and [`Add-Content`](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/add-content?view=powershell-7.1) PowerShell cmdlets. These two cmdlets can create files in a similar fashion but `Set-Content` creates and overwrites a file while `Add-Content` will create and append to an existing file.

With PowerShell still open, run the `Set-Content` cmdlet providing it the `Path` and name of the file to create with the text you’d like the file to contain (`Value`) as shown below.

The command below will create a file called _sample.txt_ in the current working directory with the text `This is a text string` inside the file.

```powershell
Set-Content -Path .\sample.txt -Value "This is a text string"
```

> _To create the same file, simply replace `Set-Content` with `Add-Content`. The `Add-Content` will create files and will also append text to existing files._

Related:[Get-Content: Reading Text Files like a Boss in PowerShell](https://adamtheautomator.com/powershell-get-content/)

### Using the `Out-File` Cmdlet

To round out how to create a file on the command prompt with PowerShell, let’s end this tutorial with the [`Out-File`](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/out-file?view=powershell-7.1) cmdlet.

The `Out-File` cmdlet is a handy command similar to the redirection operator (`>`) previously covered in the Windows Command Prompt section. The `Out-File` cmdlet accepts input from the PowerShell console and writes that output to a file of your choosing.

With PowerShell still open, type some text (`"This is a test"`) and [pipe](https://docs.microsoft.com/en-us/powershell/scripting/learn/ps101/04-pipelines?view=powershell-7.1) that text to the `Out-File` cmdlet providing the path to the file to create (`FilePath`).

The below command will create a file called _sample.txt_ in the current working directory with the text This is a test inside.

```powershell
"This is a test" | Out-File -FilePath .\sample.txt 
```

You can see below that PowerShell created a 16-byte file called _sample.txt_.

![Creating a file with the PowerShell Out-File cmdlet](https://adamtheautomator.com/wp-content/uploads/2021/05/Untitled-2021-05-31T095847.105.png)

Creating a file with the PowerShell Out-File cmdlet

## Conclusion

In this tutorial you learned different ways to use PowerShell and Windows command prompt to create file. By now, you should know just about all the ways to create text files on the command line.

Which method do you prefer?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fcommand-prompt-to-create-file%2F&text=Utilizing%20PowerShell%20and%20Windows%20Command%20Prompt%20to%20Create%20File)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fcommand-prompt-to-create-file%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fcommand-prompt-to-create-file%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/06/26989-monitor-windows-servers-prometheus-grafana-codex.webp)

### [How to Monitor Windows Servers with Prometheus and Grafana](/monitor-windows-servers-prometheus-grafana/)

Set up Windows Server monitoring with windows\_exporter, Prometheus, Grafana, and Alertmanager. Learn how to secure port 9182, scrape targets, and validate alerts.

![](https://adamtheautomator.com/wp-content/uploads/2026/05/featured_image-11.webp)

### [How to Troubleshoot Active Directory Replication Errors](/troubleshoot-active-directory-replication-errors/)

Troubleshoot Active Directory replication errors by isolating 1311, 1722, 2087, and USN rollback issues with repadmin, dcdiag, DNS, RPC, and KCC checks.

![](https://adamtheautomator.com/wp-content/uploads/2026/04/featured_image-6.webp)

### [How to Survive the 2026 Secure Boot Certificate Expiry](/survive-2026-secure-boot-certificate-expiry-3/)

Deploy Windows UEFI CA 2023 before the June 2026 certificate expiry. Inventory devices, update OEM firmware, and trigger enrollment via Intune or PowerShell registry settings.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
