How To Make A Directory In PowerShell

In this tutorial, you will learn how to create directories using PowerShell. PowerShell is a versatile scripting language developed by Microsoft, designed for system administrators to automate tasks such as creating directories, managing files, and executing processes.

By the end of this tutorial, you will have learned how to create a new directory, specify a path, and create multiple directories in a single command.

Step 1: Open PowerShell

First, open the PowerShell console by typing “PowerShell” in the Windows search bar and selecting the “Windows PowerShell” application. You may want to open it as an administrator if you plan on creating directories in protected locations.

Step 2: Use the New-Item Command

The New-Item command is used to create a new directory. The syntax for using the New-Item command to create a directory is as follows:

Replace <Path> with the filepath of the directory you want to create. For example, if you want to create a new directory called “MyFolder” within your “Documents” directory, the command would look like:
powershell
New-Item -Path C:\Users\YourUsername\Documents\MyFolder -ItemType Directory
After executing the command, you should see an output indicating that the new directory has been created successfully:

Directory: C:\Users\YourUsername\Documents
Mode                LastWriteTime         Length Name
----                -------------         ------ ----
d-----        10/12/2021   2:30 PM                MyFolder

Step 3: Create Nested Directories

If you need to create multiple nested directories, you can do so by specifying the entire path and using the -Force parameter. The -Force parameter ensures that all missing directories in the specified path will be created as well.

For example, to create a series of directories in the following structure “ParentFolder\ChildFolder\SubChildFolder”, use the following command:

Step 4: Create Multiple Directories Simultaneously

You can create multiple directories at once by using an array to define the directory paths. In this example, three directories named “FolderA”, “FolderB”, and “FolderC” will be created under the “Documents” directory:

Full Code

Conclusion

In this tutorial, you learned how to create directories in PowerShell using the New-Item command. You can now efficiently create single directories, nested directories, and multiple directories simultaneously.

PowerShell offers a powerful way to automate tasks, making it an invaluable tool for system administrators and developers alike.