In this post, we are going to see some of the most commonly used PowerShell command new-item. It is used to create a new item depending on the context.
The new-item can create a file as well as a Registry key and more. If the new item is used on a file system, it will create a new file or a folder and add some initial values to it and if it were used on a registry, it will create a new registry key and set its value too.
- Create a new folder in PowerShell.
- Create a new file in PowerShell.
- Short form for New-Item command.
People also search:
Firstly let us see how to create a folder using PowerShell. We will also see the many advantages we get by using this command.
Create a new folder using New-Item in PowerShell:
We can create a new folder named “my movies” in a directory using the following command.
Complete instructions on the above command are as follows:
- Go to the location where you want to create a new folder.
- Click on the address bar and type PowerShell.
- This will launch PowerShell in that location.
- Now enter the command
It creates the folder as shown below.
Create a new file using New-Item in PowerShell:
We can easily create a new file using PowerShell by specifying the type of item. The below command does just that.
new-item short form (alias) and how to use it:
The new-item has a short form (alias) and it is ni. The -itemtype flag can also be replaced with -type flag. We do not need double quotes around directory and file because they do not have white-spaces in them.
The command for creating directory will look like this now:
And the create file command will look like this:
The new-item is used for creating new items depending on the context. We can create a new directory or a file with the help of the -itemtype flag.
We can simplify the command with the help of alias. The new-item is replaced with just ni and the -itemtype is replaced with -type.
If you want to know more about PowerShell, stay tuned to TecKangaroo.