- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to copy readonly and hidden files/folders in the PowerShell?
To copy the readonly and hidden items from one location to another, you need to use the –Force parameter with Copy-Item cmdlet.
When you run the command without Force parameter for the readonly/hidden files, you will get the error. An example is given below.
Example
Copy-Item D:\Temp\Readonlyfile.txt -Destination D:\TempContent\
Output
PS C:\WINDOWS\system32> Copy-Item D:\Temp\Readonlyfile.txt -Destination D:\TempContent\ Copy-Item : Access to the path 'D:\TempContent\Readonlyfile.txt' is denied. At line:1 char:1 + Copy-Item D:\Temp\Readonlyfile.txt -Destination D:\TempContent\ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: (D:\Temp\Readonlyfile.txt:FileInfo) [Copy-Item], UnauthorizedAccessException + FullyQualifiedErrorId : CopyFileInfoItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.CopyItemCommand
When you add the –Force parameter in the cmdlet, it can copy the readonly/ hidden files as well.
Example
An example is given below for the readonly file.
Copy-Item D:\Temp\Readonlyfile.txt -Destination D:\TempContent\ -Force -PassThru
Output
PS C:\WINDOWS\system32> Copy-Item D:\Temp\Readonlyfile.txt -Destination D:\TempContent\ -Force -PassThru Directory: D:\TempContent Mode LastWriteTime Length Name ---- ------------- ------ ---- -ar--- 13-01-2020 18:19 0 Readonlyfile.txt
Example
The below example is for the Hidden file.
Copy-Item D:\Temp\hiddenfile.xlsx -Destination D:\TempContent\ -Force -PassThru
Output
PS C:\WINDOWS\system32> Copy-Item D:\Temp\hiddenfile.xlsx -Destination D:\TempContent\ -Force -PassThru Directory: D:\TempContent Mode LastWriteTime Length Name ---- ------------- ------ ---- -a-h-- 13-12-2019 09:52 6182 hiddenfile.xlsx
- Related Articles
- How to display files/folders including hidden files/folders in PowerShell?
- How to get hidden files and folders using PowerShell?
- How to delete hidden files and folders using PowerShell?
- How to get only hidden files and folders in PowerShell?
- How to copy files/folders to the remote location in the PowerShell?
- How to remove hidden files and folders using Python?
- How to retrieve files and folders attributes using PowerShell?
- How to change files and folders attributes using PowerShell?
- How to delete empty files and folders using PowerShell?
- How to Zip / Unzip files or folders using PowerShell?
- How to get the readonly files using Get-ChildItem in PowerShell?
- How to copy multiple files in PowerShell using Copy-Item?
- How to copy files with the specific extension in PowerShell?
- How to get only folders but not the files in the Get-ChildItem in PowerShell?
- How to copy files of the specific extension using PowerShell?

Advertisements