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

---

- A Beginners Guide To PowerShell New-Item Tap to hide Home

- Tutorials

- Guidebooks

- Instructors

- Get Paid to Write

- Advertising

- Recommended Resources

- About Adam

                Search for:

-

-

-

-

# A Beginners Guide To PowerShell New-Item

        Published:29 November 2022 - 5 min. read

- PowerShell
- PowerShell Language

          [](https://adamtheautomator.com/author/nicholas-xuan-nguyen/)

            [Nicholas Xuan Nguyen](https://adamtheautomator.com/author/nicholas-xuan-nguyen/)

            Read [more tutorials](https://adamtheautomator.com/author/nicholas-xuan-nguyen/) by Nicholas Xuan Nguyen!

        [](https://specopssoft.com/product/specops-password-auditor/?utm_source=adamtheautomator&utm_medium=referral&utm_campaign=adamtheautomator_referral_na&utm_content=display)
        Audit Active Directory for stale users, weak passwords, and other security risks with [Specops Password Auditor](https://specopssoft.com/product/specops-password-auditor/?utm_source=adamtheautomator&utm_medium=referral&utm_campaign=adamtheautomator_referral_na&utm_content=text).

Table of Contents

- Prerequisites
- Creating Files with the PowerShell New-Item cmdlet
- Creating Directories and Sub-directories
- Creating Multiple Files with a Wildcard Character
- Overwriting Files with the New-Item cmdlet
- Recreating a Directory
- Conclusion

                XFacebookLinkedIn
                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.

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

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

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

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

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

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.

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

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

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

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

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

## 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.

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

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

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.

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"

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

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

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

 💡 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.

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

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.

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

Creating a sub-directory

2. Next, run the [Get-ChildItem](http:// command below to see the contents of the c:\\logfiles directory.

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.

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

Recreating a directory

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

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

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

  Hate ads? Want to support the writer? Get many of our tutorials packaged as an ATA Guidebook.

  [Explore ATA Guidebooks](https://adamtheautomator.com/ata-guidebooks/)

## More from ATA Learning and Partners

- ### Recommended Resources! Recommended Resources for Training, Information Security, Automation, and more!

- ### Get Paid to Write! ATA Learning is always seeking instructors of all experience levels. Regardless if you’re a junior admin or system architect, you have something to share. Why not write on a platform with an existing audience and share your knowledge with the world?

- ### ATA Learning Guidebooks ATA Learning is known for its high-quality written tutorials in the form of blog posts. Support ATA Learning with ATA Guidebook PDF eBooks available offline and with no ads!

## Categories

- IT Ops

- Cloud

- DevOps

- Home Ops

- Information Security

- Software Development

## Site

- Home

- Tutorials

- Guidebooks

- Instructors

- Get Paid to Write

- Advertising

- Recommended Resources

- About Adam

        Copyright 2026&copy; ATA Learning | [Privacy Policy](https://adamtheautomator.com/privacy/)

                                                        Don't be left behind with the ATA Learning Newsletter!

Looks like you're offline!
