Javatpoint Logo
Javatpoint Logo

PowerShell Move-Item | PowerShell Move file

The PowerShell Move-Item cmdlet moves an item from one location to another location. It moves an item, including its contents, properties, and child items, from one location to another. The Same provider must support the locations.

For instance, it can move a single file or subdirectory from one directory to another or move a registry subkey from one key to another key. The mi, mv, and move are the aliases of Move-Item cmdlet.

When we move an item, it is added to the new directory and deleted from its original directory.

Syntax


Parameters

-Path

The -Path parameter is used to specify the path to the current location of the items. Wildcard characters are accepted. By default, its value is the current directory.

-LiteralPath

The -LiteralPath parameter is used to specify a path of a location. Its value is used exactly as it is typed. If the path includes the escape characters, enclose it in single quotation marks. Single quotation mark tells the Windows PowerShell that it should not interpret any character as an escape sequence. There is no character in the cmdlet, which is interpreted as a wildcard.

-Destination

The -Destination parameter is used to specify the path to the location where the item is being copied. By default, its value is the current directory. Wildcard characters are accepted, but the output must specify a single location.

Specify a new name in the value of-Destination parameter, to rename the item being moved.

-Force

The -Force parameter is used to force the command to execute without asking for user confirmation.

-Filter

The -Filter parameter specifies a filter to qualify the -Path parameter. The FileSystem provider is the only PowerShell provider that supports the uses of filters. This parameter is more efficient as the provider applies the filters when the cmdlet gets the object, rather than having Powershell filters the object after they're accessed.

-Include

The items that this cmdlet includes in the operation are specified as a string array. The value of -Include parameter qualifies the -Path parameter. Enter a pattern or a path element, such as *.txt. Wildcard characters are accepted. The -Exclude parameter is effective only when the cmdlet includes the contents of an item, such as C:\*, the wildcard character '*' is used to specify the contents of the C: directory.

-Exclude

The items that this cmdlet excludes in operation are specified as a string array. The value of -Exclude parameter qualifies the -Path parameter. Enter a pattern or a path element, such as *.txt. Wildcard characters are accepted. The -Exclude parameter is effective only when the cmdlet includes the contents of an item, such as C:\*, the wildcard character '*' is used to specify the contents of the C: directory.

-PassThru

The -PassThru parameter returns an object that represents an item with which we are working. Be default; it does not generate any output.

-WhatIf

The -WhatIf parameter displays what would happen if the cmdlet executes. The cmdlet does not execute.

-Confirm

The -Confirm parameter prompts a confirmation before running the cmdlet.

Examples

Example 1: Move a file to another directory

PowerShell Move-Item

The cmdlet in this example moves the s.txt file from C:\drive to D:\drive.

Example 2: Move a file to another location and rename that file

PowerShell Move-Item

The cmdlet, in this example, moves the s1.txt file from D:\jtp location to D:\users location and renames it from s1.txt to sk.txt.

Example 3: Move a specified directory and its content to another directory

PowerShell Move-Item

The cmdlet, in this example, moves the C:\javatpoint directory and its contents to the C:\powershelldirectory. The javatpoint directory and all of its subdirectories and files will appear in the PowerShell directory after executing the cmdlet.

Example 4: Move all the files of a specified extension from the current directory to another directory

PowerShell Move-Item

The cmdlet, in this example, moves all of the .txt files from the current directory to the D:\powershelldirectory.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA