PowerShell New-Item | Create folder

The New-Item Cmdlet in PowerShell creates the files and folders in the file system and also creates registry keys and entries in the registry. With the creation of a file, it also adds the initial content to the file.

Syntax

Parameters

Followings are the parameters used in this cmdlet:

-Path

The -Path parameter is used to specify the path of a location of the new file or folder. Wildcard characters are accepted.

-ItemType

The -ItemType parameter specify the type of specified provider of the new item.

If the location of a user is in the file system drive, these five values (File, SymbolicLink, Directory, Junction, HardLink) are allowed.

If your location is in a certification drive, you can specify these values: Certificate Provider, Certificate, Store, StoreLocation.

-Name

This parameter specifies the new file or folder name.

-Value

This parameter is used to denote the value of a new item.

-Force

This parameter forces this cmdlet to create the items which write over existing read-only items.

-WhatIf

This parameter describes what would happen if the cmdlet executes. The cmdlet does not execute.

-Confirm

This parameter prompts you a confirmation before executing the cmdlet.

Examples

Example 1: Creates a file in the present working directory

PowerShell New-Item

The command, in this example, creates a text file in the present working directory.

Example 2: Creates a file and add the content to that file

PowerShell New-Item

The command in this example creates a text file and also passes the string to the file, which is followed by a -Value parameter in the cmdlet.

Example 3: Create a directory

PowerShell New-Item

The command in this example creates the directory in the given drive. In this command, the -ItemType parameter represents the new item in a directory.

Example 4: Create multiple files

PowerShell New-Item

The command, in this example, creates the new file in the two different directories. If you want to create multiple items, the -Path parameter accepts multiple strings.