You are currently viewing PowerShell New-Item Cmdlet

PowerShell New-Item Cmdlet

PowerShell New-Item Cmdlet

Hello Everyone

Welcome to CloudAffaire and this is Debjeet.

In the last blog post, we have discussed Clear-Content cmdlet in PowerShell.

https://cloudaffaire.com/powershell-clear-content-cmdlet/

In this blog post, we will discuss New-Item cmdlet in PowerShell. You can use New-Item cmdlet to create new files and directories in PowerShell. New-Item cmdlet can also be used to create new symbolic links, hard links, registry keys, etc by assigning appropriate value to “ItemType” argument.

New-Item Cmdlet Syntax:

New-Item Cmdlet Argument List:

  • Confirm: Prompts you for confirmation before running the cmdlet.
  • Credential: To impersonate another user or elevate your credentials.
  • Force: Forces this cmdlet to create an item that writes over an existing read-only item.
  • ItemType: Specifies the provider-specified type of the new item. An Item can be a File, Directory, SymbolicLink, Junction or HardLink.
  • Name: Specifies the name of the new item. You can specify the name of the new item in the Name or Path parameter value, and you can specify the path of the new item in Name or Path value.
  • Path: Specifies the path of the location of the new item. The default is the current location when Path is omitted. You can specify the name of the new item in Name, or include it in Path.
  • UseTransaction: Includes the command in the active transaction. This parameter is valid only when a transaction is in progress.
  • Value: Specifies the value of the new item. You can also pipe a value to New-Item.
  • WhatIf: Shows what would happen if the cmdlet runs. The cmdlet is not run.

PowerShell New-Item Cmdlet:

Create A New Directory In PowerShell:

Create A Chain Of Directories And Sub-Directories In PowerShell:

Create Multiple Directories At Once In PowerShell:

Create A New File In PowerShell:

Create A New File With Content In PowerShell:

Create Multiple Files At Once In PowerShell:

Hope you have enjoyed this article. In the next blog post, we will discuss Remove-Item cmdlet in PowerShell.

To get more details on PowerShell, kindly follow below official documentation

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about?view=powershell-5.1

 

Leave a Reply