PowerShell Logo Small

New-Item



This is the built-in help made by Microsoft for the command 'New-Item', in PowerShell version 2 - as retrieved from Windows version 'Microsoft® Windows Vista™ Ultimate ' PowerShell help files on 2016-06-23.

For PowerShell version 3 and up, where you have Update-Help, this command was run just before creating the web pages from the help files.

SYNOPSIS

Creates a new item.

SYNTAX


New-Item [-Path] <string[]> [-Credential <PSCredential>] [-Force] [-ItemType <string>] [-Value <Object>] [-Confirm] [-WhatIf] [-UseTransaction] [
<CommonParameters>]
New-Item -Name <string> [[-Path] <string[]>] [-Credential <PSCredential>] [-Force] [-ItemType <string>] [-Value <Object>] [-Confirm] [-WhatIf] [-
UseTransaction] [<CommonParameters>]



Search powershellhelp.space

DESCRIPTION


The New-Item cmdlet creates a new item and sets its value. The types of items that can be created depend upon the location of the item. For examp
le, in the file system, New-Item is used to create files and folders. In the registry, New-Item creates registry keys and entries.

New-Item can also set the value of the items that it creates. For example, when creating a new file, New-Item can add initial content to the file
.



<

RELATED LINKS

Online version: http://go.microsoft.com/fwlink/?LinkID=113353
about_Providers
Get-Item
Set-Item
Remove-Item
Clear-Item
Invoke-Item
Rename-Item
Move-Item
Copy-Item

REMARKS

<

Examples


-------------------------- EXAMPLE 1 --------------------------

C:\PS>new-item -path . -name testfile1.txt -type "file" -value "This is a text string."



Description
-----------
This command creates a text file named testfile1.txt in the current directory. The dot (.) in the value of the Path parameter indicates the curre
nt directory. The quoted text that follows the Value parameter is added to the file as content.








-------------------------- EXAMPLE 2 --------------------------

C:\PS>new-item -path c:\ -name logfiles -type directory



Description
-----------
This command creates a directory named Logfiles in the C: drive. The Type parameter specifies that the new item is a directory, not a file or oth
er file system object.








-------------------------- EXAMPLE 3 --------------------------

C:\PS>new-item -path $profile -type file -force



Description
-----------
This command creates a Windows PowerShell profile in the path that is specified by the $profile variable.

You can use profiles to customize Windows PowerShell. $Profile is an automatic (built-in) variable that stores the path and file name of the Curr
entUser/CurrentHost profile. By default, the profile does not exist, even though Windows PowerShell stores a path and file name for it.

In this command, the $profile variable represents the path to the file. The Type parameter (or InfoType) specifies that the command creates a fil
e. The Force parameter lets you create a file in the profile path, even when the directories in the path do not exist (Windows PowerShell creates
them).

After you use this command to create a profile, you can enter aliases, functions, and scripts in the profile to customize your shell.

For more information, see about_Automatic_Variables and about_Profiles.








-------------------------- EXAMPLE 4 --------------------------

C:\PS>new-item -type directory -path c:\ps-test\scripts



Description
-----------
This command creates a new Scripts directory in the C:\PS-Test directory.

The name of the new directory item, Scripts, is included in the value of the Path parameter, instead of being specified in the value of the Name
parameter. As indicated by the syntax, either command form is valid.