Copying and moving files and folders
When you are working in the operating system, there may be instances where you need to copy or move files and folders around on the operating system. PowerShell provides two cmdlets to copy and move files. The copy-item
cmdlet allows you to copy a file or a folder from one location to another. The proper syntax of this cmdlet is calling copy-item
, followed by –path
argument for the source you want to copy and the –destination
argument for the destination of the file or folder. The copy-item
cmdlet also has the –force
argument to write over a read-only or hidden file. There are instances when read-only files cannot be overwritten, such as a lack of user permissions, which will require additional code to change the file attributes before copying over files or folders. The copy-item
cmdlet also has a –recurse
argument, which allows you to recursively copy the files in a folder and its subdirectories.
Tip
A common trick to use with the copy-item
cmdlet is to...