Coding Ref

How to create a directory in PowerShell

How to create a directory in PowerShell

To create a new directory in PowerShell, use the New-Item cmdlet with the directory parameter.

This cmdlet takes the path and name of the new directory as input, and creates the directory at the specified location.

For example, to create a new directory named mydir in the current directory, you can use the following PowerShell command:

New-Item -ItemType directory -Path .\mydir

This command will create a new directory named mydir in the current directory.

If the directory already exists, the cmdlet will not create a new directory, and will instead display an error message.

To create a new directory and any intermediate directories that do not exist, you can use the Force parameter with the New-Item cmdlet, as follows:

New-Item -ItemType directory -Path .\mydir -Force

This command will create a new directory named mydir in the current directory, and will also create any intermediate directories that do not exist.

For example, if the mydir directory is located two levels below the current directory, and the intermediate directories do not exist, this command will create the two intermediate directories as well as the mydir directory.

The New-Item cmdlet is used to create various types of items, such as files, directories, and symbolic links, in addition to directories. The ItemType parameter is used to specify the type of item to be created, and can be set to directory to create a new directory.

Conclusion

To create a new directory in PowerShell, use the New-Item cmdlet with the directory parameter.

You'll also like

Related tutorials curated for you

    How to write multiple-line comments in PowerShell

    How to declare global variables in PowerShell

    What is Write-Host in PowerShell?

    How to install PowerShell on Mac

    How to create a directory in PowerShell

    How to print output in PowerShell

    What is read-host in PowerShell?

    Add-Content in PowerShell

    How to use Robocopy in PowerShell

    String formatting in PowerShell

    How to unzip a file in Powershell

    How to rename a file in PowerShell