---
title: "A Beginners Guide To PowerShell New-Item"
description: "Get started with PowerShell New-Item in this beginner’s guide to creating new items and folders within PowerShell!"
canonical: "https://adamtheautomator.com/powershell-new-item/"
---

# A Beginners Guide To PowerShell New-Item

> Get started with PowerShell New-Item in this beginner’s guide to creating new items and folders within PowerShell!

Source: https://adamtheautomator.com/powershell-new-item/

---

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/)

![A Beginners Guide To PowerShell New-Item](https://adamtheautomator.com/wp-content/uploads/2022/11/powershell-new-item.jpg)

# A Beginners Guide To PowerShell New-Item

[![](https://secure.gravatar.com/avatar/2788bb1a3f735603f81eca51d68daec56a9d97e805a10268fb2c20afcc76b81b?s=192&d=mm&r=g)Nicholas Xuan Nguyen](https://adamtheautomator.com/author/nicholas-xuan-nguyen/)29 November 20225 min. read

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

Tags:[PowerShell](/tag/powershell/)[PowerShell Language](/tag/powershell-language/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Creating Files with the PowerShell New-Item cmdlet](#creating-files-with-the-powershell-new-item-cmdlet)
*   [Creating Directories and Sub-directories](#creating-directories-and-sub-directories)
*   [Creating Multiple Files with a Wildcard Character](#creating-multiple-files-with-a-wildcard-character)
*   [Overwriting Files with the New-Item cmdlet](#overwriting-files-with-the-new-item-cmdlet)
*   [Recreating a Directory](#recreating-a-directory)
*   [Conclusion](#conclusion)

PowerShell is a robust source shell and scripting language that houses tons of cmdlets. But as a beginner, you may first want to look into the PowerShell `New-Item` cmdlet. This cmdlet is one of the essential cmdlets as it allows you to create new items.

In this tutorial, you will learn how to use the `New-Item` cmdlet to create items, like files and directories, by running a single command.

Dive in and get started creating items in PowerShell!

## Prerequisites

This tutorial comprises hands-on demonstrations. To follow along, you will need an operating system with PowerShell installed. This tutorial uses Windows 10 and PowerShell 7.

Related:[PowerShell 7 Upgrade : A How to Walk Through](https://adamtheautomator.com/powershell-7-upgrade/)

## Creating Files with the PowerShell `New-Item` cmdlet

Perhaps you need to create new files while in PowerShell. If so, the `New-Item` cmdlet will do the trick. This cmdlet is handy since you do not have to switch between different windows to create items.

The basic syntax for a `New-Item` command is as follows where:

| Parameter | Function |
| --- | --- |
| \-Path | Specifies the location to create the item. |
| \-Name | Provides the name of the item. |
| \-ItemType | Sets the type of item to create (i.e., a text file, PowerShell script, or even an image file.) |
| \-Value | Inputs the item’s value, such as text, string, numbers, or even other cmdlets. |

```powershell
New-Item -Path <path> -Name <String> -ItemType <String> -Value <Object>
```

To see how the New-Item works in creating files:

1\. Run the below command to create a new file named `file.txt` with the value `"powershell new-item demo file current directory."` in the working directory (`-Path .`)

```powershell
New-Item -Path . -Name "file.txt" -ItemType "file" -Value "powershell new-item demo file current directory."
```

![Creating a file in the working directory](https://adamtheautomator.com/wp-content/uploads/2022/11/image-407.png)

Creating a file in the working directory

2\. Next, open File Explorer, look for and open the text file (_file.txt_) you created in your preferred text [editor](https://adamtheautomator.com/powershell-text-editor/) to verify the file.

![PowerShell new-item : Verifying the file was created](https://adamtheautomator.com/wp-content/uploads/2022/11/image-408.png)

PowerShell new-item : Verifying the file was created

Related:[How to Edit Files with a Real PowerShell Text Editor](https://adamtheautomator.com/powershell-text-editor/)

3\. Now, run the below command to create multiple text files (_`log1.txt`_ and `*log2.txt*`), where commas separate the paths (`c:\\logfiles`).

```powershell
New-Item -ItemType "file" -Path "c:\logfiles\log1.txt", "c:\logfiles\log2.txt"
```

![Creating multiple files](https://adamtheautomator.com/wp-content/uploads/2022/11/image-409.png)

Creating multiple files

> 💡 _Separating the file paths in commas is ideal only if you create at least two or three files. If you plan to create a vast number of files, building [PowerShell arrays](https://adamtheautomator.com/powershell-array/) is your best option, but it is out of the scope of this tutorial._

## Creating Directories and Sub-directories

Besides creating files, the PowerShell `New-Item` cmdlet lets you create directories and sub-directories with a single command. This feature helps when creating a directory structure for your files.

The syntax for creating a directory is similar to creating a file, but you must specify the `-ItemType` as `"directory"`.

To prepare a directory structure for your files:

1\. Run the following command to create a new `directory` called `test` in the `C:\\` drive.

```powershell
New-Item -Path C:\ -Name "test" -ItemType "directory"
```

![Creating a new directory](https://adamtheautomator.com/wp-content/uploads/2022/11/image-410.png)

Creating a new directory

2\. Next, navigate to the _C:\\_ drive in File Explorer, look for, and verify the newly-created directory (_test_) exists.

![Verifying the newly-created directory](https://adamtheautomator.com/wp-content/uploads/2022/11/image-411.png)

Verifying the newly-created directory

3\. Once verified, run the below command to create a sub-directory under the C:\\reports\\images

```powershell
New-Item -Path "C:\reports\images" -ItemType "directory"
```

![Creating a sub-directory](https://adamtheautomator.com/wp-content/uploads/2022/11/image-412.png)

Creating a sub-directory

4\. Lastly, navigate to the _C:\\reports_ directory to verify the newly-created sub-directory (_images_) is present.

![Verifying the directory was created](https://adamtheautomator.com/wp-content/uploads/2022/11/image-413.png)

Verifying the directory was created

## Creating Multiple Files with a Wildcard Character

Perhaps you are looking for a way to create log files for each week of the month in one go. In that case, a wildcard character works the magic, specifically the character. The wildcard character can be helpful when you wish to create multiple files or directories with similar names.

Run the below command to create log files with the same name (`logs.txt`) in all (`*`) existing sub-directories called _week1, week2, week3,_ and _week4._ The `[[Select-Object](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/select-object?view=powershell-7.3)]` cmdlet is piped to the `New-Item` cmdlet to print the full path of each created log file.

```powershell
New-Item -Path C:\\logfiles\\* -Name logs.txt -ItemType File | Select-Object FullName
```

![Creating files using a wildcard character](https://adamtheautomator.com/wp-content/uploads/2022/11/image-414.png)

Creating files using a wildcard character

Related:[How To Use the PowerShell Expand Property for Select-Object](https://adamtheautomator.com/powershell-expand-property/)

## Overwriting Files with the `New-Item` cmdlet

When you create a new item, such as a file or directory, with the PowerShell `New-Item` cmdlet, you will get an error message saying the item already exists, as shown below.

![Getting an error creating a file that already exists](https://adamtheautomator.com/wp-content/uploads/2022/11/image-415.png)

Getting an error creating a file that already exists

But perhaps, you wish to overwrite a log file each time a scheduled task executes. If so, appending the `-Force` parameter lets you forcefully overwrite files without getting a prompt or error message.

1\. Run the following command to create a new `file` named `log3.txt` in the `c:\\logfiles` directory with the content `Log File 3 content.`

```powershell
New-Item -ItemType "file" -Path "c:\logfiles\log3.txt" -Value 'Log File 3 content.'
```

Next, run the [`Get-Content`](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-content?view=powershell-7.3) command below to get the content of the `log3.txt` file. `Get-Content "c:\\logfiles\\log3.txt"`

```powershell
Get-Content "c:\logfiles\log3.txt"
```

![Logfile 3 Content](https://adamtheautomator.com/wp-content/uploads/2022/11/image-416.png)

Logfile 3 Content

Related:[PowerShell Get-Content a PowerShell](https://adamtheautomator.com/powershell-get-content/)

3\. Now, run the below command to forcefully (`-Force`) overwrite the existing log file (`log3.txt`) with new content (`Log File 3 content. Hello world`).

```powershell
New-Item -ItemType "file" -Path "c:\logfiles\log3.txt" -Value 'Log File 3 content. Hello world' -Force
```

![Using the -Force parameter to overwrite an existing file](https://adamtheautomator.com/wp-content/uploads/2022/11/image-443.png)

Using the `-Force` parameter to overwrite an existing file

> 💡 _Take caution when using the `-Force` parameter, as it can overwrite existing files without warning._

4\. Now, run the following command to verify the content of the overwritten log file.

```powershell
Get-Content "c:\logfiles\log3.txt"
```

![Verifying modified content of the log3.txt file](https://adamtheautomator.com/wp-content/uploads/2022/11/image-444.png)

Verifying modified content of the _log3.txt_ file

## Recreating a Directory

Suppose an existing directory is corrupted. Like overwriting a file, you can recreate that corrupted directory using the `-Force` parameter to fix it. But note that, unlike files, you cannot overwrite directories.

When you use the `-Force` parameter to recreate a directory, the `New-Item` cmdlet simply returns the object of the existing directory. The files or subdirectories inside the recreated director remain intact.

1\. Run the below command to create a sub-directory called _`force-demo`_ in the `c:\\logfiles` directory. This sub-directory is just to demonstrate the impact of recreating its parent directory.

```powershell
New-Item -Path "c:\logfiles\force-demo" -ItemType Directory
```

![Creating a sub-directory](https://adamtheautomator.com/wp-content/uploads/2022/11/image-445.png)

Creating a sub-directory

2\. Next, run the [`Get-ChildItem`](http://%3Chttps://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-childitem?view=powershell-7.3) command below to see the contents of the `c:\\logfiles` directory.

![Listing the contents of the c:\\logfiles directory](https://adamtheautomator.com/wp-content/uploads/2022/11/image-446.png)

Listing the contents of the _c:\\logfiles_ directory

Related:[Get-ChildItem: Listing Files, Registry, and Certificates](https://adamtheautomator.com/get-childitem/)

3\. Next, run the below command to forcefully (`-Force`) recreate the `c:\\logfiles` directory.

```powershell
New-Item -Path "c:\logfiles" -ItemType Directory -Force
```

![Recreating a directory](https://adamtheautomator.com/wp-content/uploads/2022/11/image-447.png)

Recreating a directory

4\. Lastly, rerun the same `Get-ChildItem` command below to verify the contents of the recreated directory (`c:\\logfiles`).

```powershell
Get-ChildItem  "c:\logfiles"
```

As you can see, the directory is successfully recreated with its file and sub-directory intact.

![Using the -Force Parameter to recreate an existing dir](https://adamtheautomator.com/wp-content/uploads/2022/11/image-446.png)

Using the -Force Parameter to recreate an existing dir

## Conclusion

This tutorial aims to teach you how the PowerShell `New-Item` cmdlet helps your workflow create files, directories, and other objects with a single command.

With the `New-Item` cmdlet, you can quickly create objects using its helpful parameters, and wildcard character without switching between windows.

Now, why not try creating your [PowerShell profile](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-item?view=powershell-7.2#example-3-create-a-profile) to write instructions to execute when you launch a PowerShell session? And, of course, these instructions can include a `New-Item` cmdlet!

Related:[PowerShell Profile : A Getting Started Guide](https://adamtheautomator.com/powershell-profile-a-getting-started-guide/)

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-new-item%2F&text=A%20Beginners%20Guide%20To%20PowerShell%20New-Item)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-new-item%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fpowershell-new-item%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2023/08/powershell-approved-verbs.jpg)

### [Your Getting Started Guide to PowerShell Approved Verbs](/powershell-approved-verbs/)

Discover how to get started with PowerShell Approved Verbs to make sure your scripts and code is top-notch in this ATA Learning tutorial!

![](https://adamtheautomator.com/wp-content/uploads/2023/07/powershell-sort-object.jpg)

### [Learning PowerShell Sort-Object with Examples](/powershell-sort-object/)

Learn all of the ins-and-outs of the PowerShell Sort-Object cmdlet in this example driven tutorial by ATA Learning!

![](https://adamtheautomator.com/wp-content/uploads/2023/03/powershell-change-directory.jpg)

### [PowerShell Change Directory: Navigating Your File System](/powershell-change-directory/)

Learn how to use the PowerShell change directory command to navigate your file system with ease. Master the basics of PowerShell file navigation today.

## 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/)
