PowerShell 7.3 - Difficulty with Recursive Directory Copy while Preserving File Attributes
I've been struggling with this for a few days now and could really use some help. This might be a silly question, but I'm attempting to use PowerShell 7.3 to recursively copy a directory while preserving all file attributes, including creation date, last write time, and security settings. I've been using the `Copy-Item` cmdlet but I noticed that it doesn't preserve the security attributes, and I want to ensure everything is retained during the copy process. Hereβs the command I initially tried: ```powershell Copy-Item -Path 'C:\SourceDirectory' -Destination 'D:\DestinationDirectory' -Recurse ``` While this works for copying files, I get the following warning for the security attributes: ``` Warning: Securing of the copied items was not successful. This item may not have all security attributes copied. ``` I've also tried using `-Force` and `-Preserve` parameters, but those don't seem to solve the scenario either. I came across `robocopy`, which looks promising for my needs, and I attempted the following: ```powershell robocopy 'C:\SourceDirectory' 'D:\DestinationDirectory' /E /COPYALL /DCOPY:T ``` This command successfully copies everything, including the attributes, but I find that it tends to be slower than `Copy-Item` for large directories with many small files. Is there a way to achieve a balance between speed and preserving all file attributes using PowerShell, or should I continue using `robocopy` despite its performance optimization? Any advice or alternative approaches would be greatly appreciated! What am I doing wrong? I'm working on a application that needs to handle this. Thanks in advance!