Copy-Item does not retain Hidden attribute
See original GitHub issueCopied items do not retain their attributes.
Steps to reproduce
md temp1
md temp2
cd .\temp1\
git init
(Get-Item .\.git\ -Force).Attributes
# Output: Hidden, Directory
Copy-Item * ..\temp2\ -Recurse -Force
cd ..\temp2\
(Get-Item .\.git\ -Force).Attributes
# Output: Directory
Expected behavior
The .git folder should still have the Hidden attribute after it is copied.
Actual behavior
The .git folder no longer has the Hidden attribute.
Environment data
$PSVersionTable
Name Value
---- -----
PSVersion 7.0.3
PSEdition Core
GitCommitId 7.0.3
OS Microsoft Windows 10.0.18362
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (3 by maintainers)
Top Results From Across the Web
Powershell Copy-Item -force doesn't preserve invisible ...
Is there a simple method to copy hidden folders as they are or do I need to iterate over each copied item and...
Read more >Should copy-item perhaps preserve attribute hidden for ...
I'm currently working with DISM in WinPE... There's no PS equivalent cmdlet for ROBOCOPY or XCOPY. ROBOCOPY /COPY:DATSO /E ROBOCOPY /DCOPY:DAT / ...
Read more >Copy-Item (Microsoft.PowerShell.Management)
The Copy-Item cmdlet copies an item from one location to another location in the same namespace. ... This cmdlet doesn't cut or delete...
Read more >PowerShell Copy Item examples
We can use Copy-Item to copy an item from one location to another. The command only copies the item, it will not cut...
Read more >Hide-When attributes do not correspond to field level ...
When you bring the information to the destination field, you notice that hide-when attributes are enabled that do not correspond to the field...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

It is not clear - today we copy only file attributes:
It seems we get a complex behavior and it can confuse users. I’d prefer more simple UX.
Since file attributes are coped by default should new parameter be -IncludeDirectoryAttributes? And what about with Exclude in the case? Have -ExcludeFileAttributes only or -ExcludeDirectoryAttributes too?
I tested with Far Manager - it copies directory attributes by default. If this feature is present and gone then it will definitely be a bucket 3 breaking change. But if this feature is not present, and it will be added, then this is definitely not a breaking change. (Those to whom it is important use a workaround today. Those who don’t care ignore it at all.)
My proposal is:
We have about 1 year for getting feedbacks and adoption.
@PowerShell/powershell-committee reviewed this again, we agree on an experimental feature that copies the directory attributes. In addition, not having any
-ExcludeDirectoryAttributesswitch initially unless customer feedback makes it clear this is needed. In the case of someone copying a ReadOnly directory and subsequently trying to write to it because it worked previously they would get a clear error message and should update their script to modify the directory attribute explicitly.