EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials PowerShell Tutorial PowerShell New-Item
Secondary Sidebar
PowerShell Tutorial
  • cmdlet
    • PowerShell Wait
    • PowerShell Match
    • cmdlets in PowerShell
    • Start PowerShell from cmd
    • Add-Content in PowerShell
    • Get Help in PowerShell
    • PowerShell Copy-Item
    • PowerShell Remove-Item
    • PowerShell Move-Item
    • Get Command in PowerShell
    • PowerShell Run Command
    • Windows PowerShell ISE
    • Windows Powershell Commands
    • WinRM PowerShell
    • PowerShell Date
    • Powershell Write-Host
    • PowerShell Get-ChildItem
    • PowerShell Sort-Object
    • PowerShell Where Object
    • PowerShell Set-Content
    • PowerShell Set-Location
    • PowerShell Invoke-Command
    • PowerShell Invoke-Webrequest
    • PowerShell Get-Location
    • PowerShell Get-Date
    • PowerShell Get-Service
    • PowerShell Test-Path
    • Powershell Module Path
    • PowerShell Out-File
    • PowerShell if File Exists
    • Powershell Copy File
    • PowerShell Delete File
    • PowerShell New-Item
    • PowerShell Rename-Item
    • PowerShell ComputerName
    • PowerShell Get-Content
    • PowerShell Get-Item
    • PowerShell Get-ADUser
    • PowerShell Grep
    • PowerShell Concatenate String
    • PowerShell Get-Process
    • PowerShell Count
    • PowerShell pause
  • Basics
    • PowerShell Restart Service
    • PowerShell comment
    • PowerShell Map Network Drive
    • PowerShell Append to File
    • PowerShell print
    • What is PowerShell
    • Uses Of Powershell
    • PowerShell Empire
    • PowerShell Parameter
    • PowerShell Stop Service
    • PowerShell Versions
    • How To Install PowerShell
    • PowerShell uninstall module
    • How to Use PowerShell?
    • PowerShell Logging
    • PowerShell Tools
    • PowerShell Commands
    • PowerShell Version Command
    • PowerShell Administrator
    • PowerShell Modules
    • PowerShell Registry
    • PowerShell block Comment
    • PowerShell Verbs
    • PowerShell list
    • PowerShell add user to group
    • PowerShell Write to Console
    • Variable in PowerShell
    • PowerShell New Line
    • PowerShell prompt for input
    • PowerShell File Extension
    • Powershell Remotesigned
    • PowerShell Write to File
    • PowerShell Ping
    • PowerShell wget
    • PowerShell Global variable
    • PowerShell Get-ADGroup
    • Array in PowerShell
    • PowerShell Multidimensional Array
    • PowerShell Array of Strings
    • PowerShell? join array
    • Useful PowerShell Scripts
    • String in PowerShell
    • PowerShell Switch Statement
    • PowerShell Function Parameters
    • PowerShell vs PowerShell ISE
    • PowerShell test-connection
    • PowerShell Test-NetConnection
    • PowerShell GUI
    • PowerShell Variable in String
    • PowerShell Active Directory
  • Variables
    • PowerShell Variables
    • PowerShell Environment Variables
    • PowerShell set environment variable
    • Hashtable in PowerShell
    • Set Variable in PowerShell
  • Operators
    • PowerShell Operators
    • Comparison Operators in PowerShell
    • Logical Operators in PowerShell
    • PowerShell Boolean
    • PowerShell Like Operator
  • Control Statements
    • If Statement in PowerShell
    • If Else in PowerShell
    • Else If in PowerShell
    • Loops in PowerShell
    • For loop in PowerShell
    • PowerShell While Loop
    • PowerShell do while
    • PowerShell Loop through Array
    • PowerShell add to array
    • PowerShell ForEach Loop
    • PowerShell Break
    • PowerShell Continue
    • Switch Case in PowerShell
    • PowerShell If-Not
    • Try-catch in PowerShell
  • Functions
    • PowerShell Functions
    • PowerShell String Functions
    • powershell nslookup
    • PowerShell here string
    • PowerShell Wildcards
    • Regex in PowerShell
    • PowerShell not like
    • PowerShell Filter
    • PowerShell Sleep
    • PowerShell where
    • PowerShell join string
    • PowerShell Exit
    • PowerShell null
    • PowerShell Dictionary
    • PowerShell Location
    • PowerShell Start-Service
    • PowerShell is not digitally signed
    • PowerShell Uptime
    • PowerShell Create Directory
    • PowerShell Trim
    • PowerShell Join-Path
    • PowerShell Execution Policy
    • PowerShell SubString
    • PowerShell Format Table
    • PowerShell Import Module
    • PowerShell ForEach Object
    • PowerShell Alias
    • PowerShell Scheduled Task
    • PowerShell Convert String to Date
    • PowerShell Split String
    • PowerShell Multiline String
    • PowerShell MultiLine Comment
    • PowerShell Rename Folder
    • PowerShell Delete Folder
    • PowerShell String Replace
    • PowerShell join
    • PowerShell xcopy
    • PowerShell Base64
    • PowerShell Tail
    • PowerShell User List
    • PowerShell remove User from group
    • PowerShell JSON Format
    • PowerShell Send Mail
    • PowerShell Convert to String
    • PowerShell Start-Process
    • PowerShell change directory
    • PowerShell Open File
    • PowerShell Batch File
    • PowerShell ZIP
    • PowerShell unzip
    • PowerShell XML
    • PowerShell XML Parsing
    • Remote PowerShell
    • PowerShell Escape Character
    • PowerShell scriptblock
    • PowerShell Executable Location
    • PowerShell Import-CSV?
    • PowerShell Export CSV
  • Interview Questions
    • PowerShell Interview Questions

Related Courses

Shell Scripting Course

All in One Data Science Courses

Data Visualization Courses

PowerShell New-Item

By Priya PedamkarPriya Pedamkar

powershell new item

Introduction to PowerShell New-Item

Its name itself is explaining about its behaviour. So you are thinking it is going to create something new so you are totally correct. So basically new-Item command is used if we wanted to create any new item. The new item can be any file inside a directory or multiple files inside one directory. New Item allows us to create files inside multiple directories in one execution. The good thing about the New-Item command is it will create a file inside folders and registry inside the registry. Even we can write commands to create a file inside the folder along with writing some contents on the file.

Syntax in PowerShell New-Item

Below are the syntax of PowerShell New-Item:

Syntax #1

New-Item
[-Path] <String path where new item will be created>
[-ItemType <Type of item going to be created like file, folder etc>] [-Value <Object of value of new item>] [-Force<create new item even read only access>] [-Credential <PSCredential>] [-WhatIf<display outcome of command execution>] [-Confirm<display prompt for yes or not>] [<CommonParameters>]

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Syntax #2

New-Item
[[-Path] <String path where new item will be created>] -Name <Name of new item to be created>
[-ItemType <Type of item going to be created like file, folder etc>] [-Value <Object of value of new item>] [-Force<create new item even read only access>] [-Credential <PSCredential>] [-WhatIf<display outcome of command execution>] [-Confirm<display prompt for yes or not>] [<CommonParameters>]

Parameters in New-Item PowerShell

The following points explain the parameters in PowerShell new-item:

1. Confirm: It ‘s a very useful command, suppose you are going to run a command which will create a new file and if the same file exists in a folder it will replace it. So, in this case, there are chances that you may replace any important file. In that case, it is advisable to use confirm the command, as it will give a warning before executing the command, and it will ask for your confirmation with the prompt box where it will ask you to enter yes or no. If you enter yes it will execute command else it will not execute the command.

2. Force: Force command will be used with new item creation when there are less right to perform. So for example, if you do not have write access to directories that means you have only read access, in that case, we can use force new item creation command. In the case of the existing item also it will be used. it will create a new item forcefully.

3. ItemType: We learned that we can add a new item, but the question is what are those items which we can add. We can add many things like a new item that is given below.

  • We can any Directories as an item
  • We can add a file or multiple files in a directory
  • We can also create a Symbolic link
  • We can add Junction as a new item
  • We can add a hard link as the new item

Other than these kinds of a new item we can add items in Certificate drive, they are given below

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (86,527 ratings)
  • We can add any Certificate provider as the new item
  • We can add the certificate as the new item
  • We can add store a new item
  • We can add store location as a new item

4. Name: Defines the name of the item which is going to be added. This name can be defined in name and path parameter values. We can also define a new item path in name or path value.

5. Path: This defines the path for the new item which is going to be created. The good thing is we can also use wildcard characters for the pathname. For example, we can write “*” as the pathname which means perform the creation of a new file or items inside all the folders on the root directories.

6. Value: This command defines the new item value it may be the name of any file or directory. The provided value will be added to the defined path. We will see more in the example section.

7. WhatIf: Many times when we are going to execute any command we do not know the outcome of the execution of the command, so with the help of -WhatIf command, we will able to predict the outcome of the execution of the command. For safety, we can use this command.

Examples to Implement PowerShell New-Item

Below are the examples to implement the New-Item in PowerShell:

Example #1

See the below example here we are creating a file with name test4.txt inside the ranjan1 directory. On execution of the command, it created a file test4.txt inside the ranjan1 directory. The file which we created contains the value argument inside the file which is “This world is a very beautiful place.”

Code:

New-Item -Path ./ranjan1/ -Name "test4.txt" -ItemType "file" -Value "This world is very beautyful place.”

Output:

PowerShell New-Item - 1

Example #2

See the below example here we are creating a folder with name childFolder inside the ranjan1 directory. On execution of the command, it created a file childFolder inside the ranjan1 directory. See the example below along with screens.

Code:

New-Item -Path "./ranjan1" -Name "childFolder" -ItemType "directory"

Output:

childFolder inside

Example #3

In this example, we are creating two files with the name child1 and child2 by running a single command. In the command, we can see we are passing -ItemType in item type we are passing file.

Code:

New-Item -ItemType "file" -Path "./ranjan1/child1", "./ranjan2/child2"

Output:

child1 and child2

Example #4

In the below command we are creating a file common.txt inside all the directories inside the root. Because we are using wildcard here, that means we are using “*” it will create common.txt file inside all directories of current directories.

 Code:

New-Item -Path *

-Name common.txt -ItemType File | Select-Object FullName

Output:

PowerShell New-Item - 4

Example #5

Here in this example, we are creating a symlink file, we are assigning symlink command execution value to a variable called $symboliclink and getting it to value we can see in the below example along with the screen. The creation of symlinks is useful if you wanted to an auto reflection of changes of one file inside many directories without changing many places, which means a change in one file and it will reflect in all other symlinked files in any directories.

 Code:

$symboliclink = New-Item -ItemType SymbolicLink -Path ./ranjan5/ -Target ./ranjan1/test2.txt
$symboliclink | Select-Object LinkType, Target

Output:

PowerShell New-Item - 5

Conclusion

From this tutorial, we learned that the command New-Item can create various types of item within multiple places. We also learned that we can create a single item inside multiple places with a single command. This command can be very useful for performing the creation of too many files on a repeated time basis as it will create everywhere on one command.

Recommended Articles

This is a guide to PowerShell New-Item. Here we discuss the syntax, parameters, and examples to implement new-item in Powershell with proper codes and outputs. You can also go through our other related articles to learn more –

  1. PowerShell Multidimensional Array
  2. Try-catch in PowerShell
  3. PowerShell Versions
  4. How to Implement PowerShell Rename-Item?
Popular Course in this category
All in One Data Science Bundle (360+ Courses, 50+ projects)
  360+ Online Courses |  1500+ Hours |  Verifiable Certificates |  Lifetime Access
4.7
Price

View Course

Related Courses

Shell Scripting Training (4 Courses, 1 Project)4.9
Data Visualization Training (15 Courses, 5+ Projects)4.8
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more