Coding Ref

How to create new items in PowerShell

How to create new items in PowerShell

To create new items in PowerShell, you can use the New-Item cmdlet.

This cmdlet allows you to create a variety of different types of items, such as files, directories, and registry keys.

Examples

Example 1: Create a new file

Here is an example of how to use the New-Item cmdlet to create a new file:

New-Item -Path C:\MyFolder\MyFile.txt -ItemType File

This will create a new file named MyFile.txt in the C:\MyFolder directory.

Example 2: Create a new folder or directory

To create a new directory, you can use the New-Item cmdlet with the -ItemType Directory parameter, like this:

New-Item -Path C:\MyFolder\MyDirectory -ItemType Directory

This will create a new directory named MyDirectory in the C:\MyFolder directory.

Example 3: Create a new registry key

To create a new registry key, you can use the New-Item cmdlet with the -ItemType Registry parameter, like this:

New-Item -Path HKEY_LOCAL_MACHINE\SOFTWARE\MyCompany\MyKey -ItemType Registry

This will create a new registry key named MyKey in the HKEY_LOCAL_MACHINE\SOFTWARE\MyCompany hive.

Conclusion

To create new items in PowerShell, you can use the New-Item cmdlet.

You'll also like

Related tutorials curated for you

    What is PowerShell ExpandProperty?

    Piping in PowerShell

    How to print output in PowerShell

    PowerShell do-while loop

    How to get processes in PowerShell

    How to create an alias in PowerShell

    How to move items in PowerShell

    How to use If Else in PowerShell

    How to get the host or computer name in PowerShell

    How to rename a folder in PowerShell

    What is IEX in PowerShell?

    How to count objects in PowerShell