Move-Item

 

Additional Resources for Move-Item

 

Moving a File or Folder

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

 

 

SYNOPSIS

Moves an item from one location to another.

 

SYNTAX

Move-Item [-path] <string[]> [[-destination] <string>] [-include <string[]>] [-exclude <string[]>] [-filter <string>] [-force] [-passThru] [-credential <PSCredential>] [-whatIf] [-confirm] [<CommonParameters>]

 

Move-Item [-literalPath] <string[]> [[-destination] <string>] [-include <string[]>] [-exclude <string[]>] [-filter <string>] [-force] [-passThru] [-credential <PSCredential>] [-whatIf] [-confirm] [<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

 

-path <string[]>

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

 

Required?

true

Position?

1

Default value

<current location>

Accept pipeline input?  

true (ByValue, ByPropertyName)

Accept wildcard characters? 

true

 

-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 Destination.

 

Required?

false

Position?

2

Default value

<current location>

Accept pipeline input?  

true (ByPropertyName)

Accept wildcard characters? 

true

 

-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.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

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.

 

Required?

false

Position?

named

Default value

 

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.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-force <SwitchParameter>

Overrides restrictions that prevent the command from succeeding, just so the changes do not compromise security. For example, Force will override the read-only attribute or create directories to complete a file path, but it will not attempt to change file permissions.

 

Required?

false

Position?

named

Default value

False

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-passThru <SwitchParameter>

Passes the object created by this cmdlet through the pipeline. By default, this cmdlet does not pass any objects through the pipeline.

 

Required?

false

Position?

named

Default value

False

Accept pipeline input?  

false

Accept wildcard characters? 

false

 

-credential <PSCredential>

Uses a credential to validate access to the file. <Credential> represents a user-name, such as "User01" or "Domain01\User01", or a PSCredential object, such as the one retrieved by using the Get-Credential cmdlet. If you type a user name, you will be prompted for a password. This parameter appears, but it is not supported in any Windows PowerShell core cmdlets or providers.

 

Required?

false

Position?

named

Default value

 

Accept pipeline input?  

true (ByPropertyName)

Accept wildcard characters? 

false

 

-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.

 

Required?

true

Position?

1

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

 

NOTES

 

For more information, type "Get-Help Move-Item -detailed". For technical information, type "Get-Help Move-Item -full".

 

Move-Item will move files between drives that are supported by the same provider, but it will only move directories 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.

 

When specifying multiple values for a parameter, use commas to separate the values. For example, "<parameter-name> <value1>, <value2>".

 

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

 

EXAMPLE 1

 

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

 

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".

 

EXAMPLE 2

 

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

 

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, now appear in the Logs directory.

 

EXAMPLE 3

 

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

 

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

 

EXAMPLE 4

 

gci . -recurse -include *.txt | move-item -dest C:\ps-test\TextFiles

 

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-Childitemcmdlet 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 moves only one file with each name to C:\Textfiles. The other files remain in their original directories.

 

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

 

EXAMPLE 5

 

move-item hklm:\software\mycompany\* hklm:\software\mynewcompany

 

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.

 

EXAMPLE 6

 

move-item -literalpath 'Logs[Sept`06]' -destination 'Logs[2006]'

 

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 the wildcard 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.

 

RELATED LINKS

Clear-Item

Get-Item

Invoke-Item

Set-Item

New-Item

Remove-Item

Rename-Item

Copy-Item

about_namespace

 

 

 

500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@systemmanager.forsenergy.ru to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.

Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.