New-Item

 

Additional Resources for New-Item

 

Creating a New File or Folder

http://www.microsoft.com/technet/scriptcenter/topics/msh/cmdlets/new-item.mspx

 

 

SYNOPSIS

Creates a new item in a namespace.

 

SYNTAX

New-Item [-path] <string[]> [-force] [-credential <PSCredential>] [-itemType <string>] [-value <Object>] [-whatIf] [-confirm] [<CommonParameters>]

 

New-Item [-path] <string[]> -name <string> [-force] [-credential <PSCredential>] [-itemType <string>] [-value <Object>] [-whatIf] [-confirm] [<CommonParameters>]

 

DETAILED DESCRIPTION

Creates a new item in a namespace. The type of items that can be created depend upon the Windows PowerShell provider used. New-Item is used to create files and folders when using the FileSystem provider and creates new registry keys and entries when using the Registry provider. The cmdlet can also set the value of the new item. When creating a new file, for instance, you can use New-Item to add initial content to the file.

 

PARAMETERS

 

-path <string[]>

Specifies the path to the location of the new item. Wildcards are permitted.

 

Required?

true

Position?

1

Default value

String.empty

Accept pipeline input?  

true (ByPropertyName)

Accept wildcard characters? 

false

 

-itemType <string>

Specifies the provider-specified type of the new item

 

Required?

false

Position?

named

Default value

String.empty

Accept pipeline input?   

true (ByPropertyName)

Accept wildcard characters? 

false

 

-value <Object>

Specifies the value the new item.

 

Required?

false

Position?

named

Default value

Null

Accept pipeline input?  

true (ByValue, ByPropertyName)

Accept wildcard characters? 

false

 

-name <string>

Specifies the name of the new item.

 

Required?

true

Position?

named

Default value

String.empty

Accept pipeline input?  

true (ByPropertyName)

Accept wildcard characters? 

false

 

-force <SwitchParameter>

Allows Cmdlet to override restrictions such as renaming existing files as long as security is not compromised.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-credential <PSCredential>

The credential is used to validate access. If a PSCredential object obtained by using get-credential is supplied, it will be used as is. If a user name is supplied,  there will be a prompt for a password.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

true (ByPropertyName)

Accept wildcard characters? 

false

 

-whatIf

Describes what would happen if you executed the command without actually executing the command.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-confirm

Prompts you for confirmation before executing the command.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, and -OutVariable. For more information, type, "get-help about_commonparameters".

 

INPUT TYPE

String

 

RETURN TYPE

Any

 

EXAMPLE 1

 

new-item -path . -name testfile1.txt -type "file" -value "This is a text string."

 

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

 

EXAMPLE 2

 

new-item -path c:\ -name logfiles -lype directory

 

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 other file system object.

 

EXAMPLE 3

 

new-item -path $profile -type file -force

 

The following command creates a Windows PowerShell profile in the path that is specified by the $profile variable.

 

You can use the profile to customize Windows PowerShell. $profile is an automatic (built-in) variable that stores the path and file name of your Windows PowerShell profile. By default, the profile does not exist, even though Windows PowerShell stores a path and file name for it. (To see the value of the $profile variable, type "$profile". To see a list of automatic variables, type "get-help about_automatic_variables".)

 

In this command, the $profile variable represents the path to the file. The Type parameter (or InfoType) specifies that the command creates a file (a profile is a text file). The Force parameter lets you create a file in the profile path, even when the directories in the path do not exist (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.

 

RELATED LINKS

Get-Item

Set-Item

Remove-Item

Clear-Item

Invoke-Item

Rename-Item

Move-Item

Copy-Item

about_namespace