Coding Ref

How to move items in PowerShell

How to move items in PowerShell

In PowerShell, you can use the Move-Item cmdlet to move a file or directory from one location to another. This cmdlet allows you to specify the source and destination paths, and it will move the file or directory to the specified destination.

Examples

Example 1

Here's an example of using the Move-Item cmdlet to move a file:

Move-Item -Path C:\Source\file.txt -Destination C:\Destination

In this example, the Move-Item cmdlet is used to move the file file.txt from the C:\Source directory to the C:\Destination directory.

The -Path parameter specifies the source path, and the -Destination parameter specifies the destination path. The file will be moved to the destination directory, and it will no longer be present in the source directory.

You can also use the Move-Item cmdlet to move a directory and all of its contents.

Example 2

Here's an example:

Move-Item -Path C:\Source\Directory -Destination C:\Destination -Recurse

In this example, the Move-Item cmdlet is used to move the Directory directory and all of its contents from the C:\Source directory to the C:\Destination directory.

The -Path parameter specifies the source path, and the -Destination parameter specifies the destination path. The -Recurse parameter tells the cmdlet to move the directory and all of its contents, including any subdirectories and files.

The directory and its contents will be moved to the destination directory, and they will no longer be present in the source directory.

Conclusion

The Move-Item cmdlet is a useful tool for moving files and directories in PowerShell. It allows you to specify the source and destination paths, and it will move the specified file or directory to the destination.

You'll also like

Related tutorials curated for you

    How to find the Windows version from the PowerShell command line

    How to add a user to a group in PowerShell

    How to move items in PowerShell

    What is PowerShell Grep?

    How to copy and paste into PowerShell

    How to get the current directory in PowerShell

    How to rename a computer in PowerShell

    How to use -Contains in PowerShell

    How to exclude multiple folders using Get-ChildItem in PowerShell

    What is a Scriptblock in PowerShell?

    How to use Format-Table in PowerShell

    How to restart a service in PowerShell