Copy-Item command let lets the programmer copy an item from one location to another. This has very useful implications as we will see below.
- PowerShell copy item using Copy-Item.
- Copy and rename the file.
- Copy multiple files with the same extensions.
People also search for:
PowerShell copy item using Copy-Item:
- We will move the file text.txt to the folder named folder1.
- We use the script below.
- When we check the folder1 we can see the text file copied to it.
Copy and rename the file:
- We can copy and rename the file in a single command using Powershell.
- To do this, we will provide the new name in the destination path of the copy command.
- The below steps shows this.
- We check the contents of the current folder using the below script.
- The contents of the text.txt file can be seen using this script.
- The content of the file is hello world.
- We can check the contents of the destination folder by providing the destination folder path as a parameter.
- We move the text.txt to folder1 and rename it to text1.txt using the below script.
- Checking the contents of folder1.
- Open the file using to confirm that it is the same file with a different name.
- The content of the copied file is also hello world.
Copying multiple files with the same extension:
- We have multiple text files in our current folder.
- Copying all the files is possible using Wildcard as given below.
- We can check the content of the destination folder as given below.
The output of the above script is shown in the image.
Copying files in PowerShell is a breeze. We can easily use the cpi alias for copying files from one location to another. In this post, we learned several different cases of copying files. Using these cases in the real file will take some time and practice. We recommend you to go through the post thoroughly and if there is anything, please let us know in the comments below.
For more awesome posts, stay tuned to TecKangaroo.