PowerShell is increasingly replacing the well-known DOS and Windows commands, including in the ” copying files ” area. In this short PowerShell tutorial , we would like to show you how you can use PowerShell to copy a file, files or entire folder structures relatively easily using PowerShell.
We use the new Windows Terminal , which also has a PowerShell console.
Copy file using PowerShell
The command to copy is called
and has some parameters. If you now want to copy a file, it works relatively easily with the following parameters.
Copy-Item -PATH PATH + SOURCE FILE -Destination TARGET PATH
We have shown you this once below.
This example shows how the file ” contribution.pdf ” is copied from the ” original ” to the ” copy ” directory. However, you must note that it is necessary that the target path has already been created. Otherwise there will be an error message during the copying process.
If the file already exists in the target directory, the file will not be overwritten. There would also be an error message here. You can force overwriting by using the parameter
appended to the end of the command. If you want to copy several files, you can of course also work with the wildcard “*” (eg “* .docx) .
Copy folder or structure using PowerShell
To copy a folder or an entire folder structure using PowerShell, the following command must be used.
Copy-Item -Path SOURCE PATH – Destination TARGET PATH
However, only the specified path is copied here , any subdirectories that may be included are not copied. If you want to copy these, you have to add the parameter
append to the command. The same applies here again. If the files already exist in the target folder, they will not be overwritten and an error message will appear . In this case the parameter is again
Finally, we recommend the following articles, which also deal with useful PowerShell commands .
– Update PowerShell help, listing and explanation of PowerShell commands and parameters
– Install RSAT tools via PowerShell and query installed RSAT tools
– Restart Windows service via PowerShell
– Windows Terminal – Microsoft’s new console for command prompt and PowerShell
– Export and import of a Hyper-V VM via PowerShell
Log all PowerShell commands and outputs and write them in text files – Disable pre-scrolling in the command prompt and PowerShell console
– Legacy console – Additional console settings and improvements to the command prompt & PowerShell console
– Change transparent display of the command prompt or the PowerShell console
– Command prompt (CMD) Call up PowerShell and PowerShell quickly as an administrator
– Open Command Prompt or PowerShell in full screen mode
– Replace Command Prompt with PowerShell in the Win + X menu
– Command Prompt with P Replace owershell in the start menu