Export (0) Print
Expand All

Move-Item

Updated: May 8, 2014

Applies To: Windows PowerShell 4.0

Move-Item

Moves an item from one location to another.

Aliases

The following abbreviations are aliases for this cmdlet:

  • mi, move, mv

Syntax

Parameter Set: Path
Move-Item [-Path] <String[]> [[-Destination] <String> ] [-Credential <PSCredential> ] [-Exclude <String[]> ] [-Filter <String> ] [-Force] [-Include <String[]> ] [-PassThru] [-Confirm] [-WhatIf] [-UseTransaction] [ <CommonParameters>]

Parameter Set: LiteralPath
Move-Item [[-Destination] <String> ] -LiteralPath <String[]> [-Credential <PSCredential> ] [-Exclude <String[]> ] [-Filter <String> ] [-Force] [-Include <String[]> ] [-PassThru] [-Confirm] [-WhatIf] [-UseTransaction] [ <CommonParameters>]




Detailed Description

The Move-Item cmdlet moves an item, including its properties, contents, and child items, from one location to another location. The locations must be supported by the same provider. For example, it can move a file or subdirectory from one directory to another or move a registry subkey from one key to another. When you move an item, it is added to the new location and deleted from its original location.

Parameters

-Credential<PSCredential>

Specifies a user account that has permission to perform this action. The default is the current user.

Type a user name, such as "User01" or "Domain01\User01", or enter a PSCredential object, such as one generated by the Get-Credential cmdlet. If you type a user name, you will be prompted for a password.

This parameter is not supported by any providers installed with Windows PowerShell.


Aliases

none

Required?

false

Position?

named

Default Value

Current user

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

false

-Destination<String>

Specifies the path to the location where the items are being moved. The default is the current directory. Wildcards are permitted, but the result must specify a single location.

To rename the item being moved, specify a new name in the value of the Destination parameter.


Aliases

none

Required?

false

Position?

2

Default Value

Current directory

Accept Pipeline Input?

true (ByPropertyName)

Accept Wildcard Characters?

true

-Exclude<String[]>

Omits the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as "*.txt". Wildcards are permitted.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

true

-Filter<String>

Specifies a filter in the provider's format or language. The value of this parameter qualifies the Path parameter. The syntax of the filter, including the use of wildcards, depends on the provider. Filters are more efficient than other parameters, because the provider applies them when retrieving the objects, rather than having Windows PowerShell filter the objects after they are retrieved.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

true

-Force

Allows the cmdlet to move an item that writes over an existing read-only item. Implementation varies from provider to provider. For more information, see about_Providers. Even using the Force parameter, the cmdlet cannot override security restrictions.


Aliases

none

Required?

false

Position?

named

Default Value

False

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Include<String[]>

Moves only the specified items. The value of this parameter qualifies the Path parameter. Enter a path element or pattern, such as "*.txt". Wildcards are permitted.


Aliases

none

Required?

false

Position?

named

Default Value

none

Accept Pipeline Input?

false

Accept Wildcard Characters?

true

-LiteralPath<String[]>

Specifies the path to the current location of the items. Unlike Path, the value of LiteralPath is used exactly as it is typed. No characters are interpreted as wildcards. If the path includes escape characters, enclose it in single quotation marks. Single quotation marks tell Windows PowerShell not to interpret any characters as escape sequences.


Aliases

PSPath

Required?

true

Position?

named

Default Value

None

Accept Pipeline Input?

true (ByValue, ByPropertyName)

Accept Wildcard Characters?

false

-PassThru

Passes an object representing the item to the pipeline. By default, this cmdlet does not generate any output.


Aliases

none

Required?

false

Position?

named

Default Value

False

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-Path<String[]>

Specifies the path to the current location of the items. The default is the current directory. Wildcards are permitted.


Aliases

none

Required?

true

Position?

1

Default Value

Current directory

Accept Pipeline Input?

true (ByValue, ByPropertyName)

Accept Wildcard Characters?

true

-Confirm

Prompts you for confirmation before running the cmdlet.


Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-WhatIf

Shows what would happen if the cmdlet runs. The cmdlet is not run.


Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

-UseTransaction

Includes the command in the active transaction. This parameter is valid only when a transaction is in progress. For more information, see about_Transactions


Required?

false

Position?

named

Default Value

false

Accept Pipeline Input?

false

Accept Wildcard Characters?

false

<CommonParameters>

This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see  about_CommonParameters (http://go.microsoft.com/fwlink/p/?LinkID=113216).

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.

  • System.String

    You can pipe a string that contains a path to Move-Item.


Outputs

The output type is the type of the objects that the cmdlet emits.

  • None or an object representing the moved item.

    When you use the Passthru parameter, Move-Item generates an object representing the moved item. Otherwise, this cmdlet does not generate any output.


Notes

  • Move-Item will move files between drives that are supported by the same provider, but it will move directories only within the same drive.

    Because a Move-Item command moves the properties, contents, and child items of an item, all moves are recursive by default.

    You can also refer to Move-Item by its built-in aliases, "move", "mv", and "mi". For more information, see about_Aliases.

    The Move-Item cmdlet is designed to work with the data exposed by any provider. To list the providers available in your session, type "Get-PsProvider". For more information, see about_Providers.

Examples

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

This command moves the Test.txt file from the C: drive to the E:\Temp directory and renames it from "test.txt" to "tst.txt".


PS C:\> move-item -path C:\test.txt -destination E:\Temp\tst.txt

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

This command moves the C:\Temp directory and its contents to the C:\Logs directory. The Temp directory, and all of its subdirectories and files, then appear in the Logs directory.


PS C:\> move-item -path C:\Temp -destination C:\Logs

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

This command moves all of the text files (*.txt) in the current directory (represented by a dot (.)) to the C:\Logs directory.


PS C:\> move-item -path .\*.txt -destination C:\Logs

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

This command moves all of the text files from the current directory and all subdirectories, recursively, to the C:\TextFiles directory.

The command uses the Get-ChildItem cmdlet to get all of the child items in the current directory (represented by the dot [.]) and its subdirectories that have a *.txt file name extension. It uses the Recurse parameter to make the retrieval recursive and the Include parameter to limit the retrieval to *.txt files.

The pipeline operator (|) sends the results of this command to Move-Item, which moves the text files to the TextFiles directory.

If files being moved to C:\Textfiles have the same name, Move-Item displays an error and continues, but it moves only one file with each name to C:\Textfiles. The other files remain in their original directories.

If the Textfiles directory (or any other element of the destination path) does not exist, the command fails. The missing directory is not created for you, even if you use the Force parameter. Move-Item moves the first item to a file called "Textfiles" and then displays an error explaining that the file already exists.

Also, by default, Get-ChildItem does not move hidden files. To move hidden files, use the Force parameter with Get-ChildItem.

Note: In Windows PowerShell 2.0, when using the Recurse parameter of the Get-ChildItem cmdlet, the value of the Path parameter must be a container. Use the Include parameter to specify the .txt file name extension filter (Get-ChildItem –Path .\* -Include *.txt –Recurse | Move-Item -Destination C:\TextFiles).


PS C:\> Get-ChildItem -Path .\*.txt -Recurse | Move-Item -Destination C:\TextFiles

-------------------------- EXAMPLE 5 --------------------------

This command moves the registry keys and values within the MyCompany registry key in HKLM\Software to the MyNewCompany key. The wildcard character (*) indicates that the contents of the MyCompany key should be moved, not the key itself. In this command, the optional Path and Destination parameter names are omitted.


PS C:\> move-item hklm:\software\mycompany\* hklm:\software\mynewcompany

-------------------------- EXAMPLE 6 --------------------------

This command moves the Logs[Sept`06] directory (and its contents) into the Logs[2006] directory.

The LiteralPath parameter is used instead of Path, because the original directory name includes left bracket and right bracket characters ("[" and "]"). The path is also enclosed in single quotation marks (' '), so that the backtick symbol (`) is not misinterpreted.

The Destination parameter does not require a literal path, because the Destination variable also must be enclosed in single quotation marks, because it includes brackets that can be misinterpreted.


PS C:\> move-item -literalpath 'Logs[Sept`06]' -destination 'Logs[2006]'

Related topics



Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft