1

I have the following script to recursive copy data and create a log file of the destination, could any assist please, I would like to pause for 10 seconds after each file is copied so each file allocated a different created time stamp.

$Logfile ='File_detaisl.csv'
$SourcePath = Read-Host 'Enter the full path containing the files to copy'
""
""
$TargetPath = Read-Host 'Enter the destination full path to copy the files'
""
#$str1FileName = "File_Details.csv"

Copy-Item -Path $SourcePath -Destination $TargetPath -recurse -Force

Get-ChildItem -Path $TargetPath -Recurse -Force -File  | Select-Object Name,DirectoryName,Length,CreationTime,LastWriteTime,@{N='MD5 Hash';E={(Get-FileHash -Algorithm MD5 $_.FullName).Hash}},@{N='SHA-1 Hash';E={(Get-FileHash -Algorithm SHA1 $_.FullName).Hash}} | Sort-Object -Property Name,DirectoryName | Export-Csv -Path $TargetPath$Logfile

2 Answers 2

1

Copy-Item has a -PassThru parameter that outputs each item that is currently processed. By piping to ForEach-Object you can add a delay after each file.

Copy-Item -Path $SourcePath -Destination $TargetPath -recurse -Force -PassThru | 
    Where-Object PSIsContainer -eq $false |
    ForEach-Object { Start-Sleep 10 }

The Where-Object is there to exclude folders from the ForEach-Object processing. For folder items the PSIsContainer property is $true and for files it is $false.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, the files contained within subfolders appear to have have matching creation timestamps, is there away for all files and folders to have different time stamps?
@PF6004 I cannot reproduce. Did you clear the output folder before? Btw, if you want this for folders too, remove the Where-Object line, so it waits after creation of folder as well.
0

You would lose the integrity of the folder structure, but one way to do this is using Get-ChildItem then piping to Foreach-Object, or using a loop to iterate through the items one at time.

Get-ChildItem -Path $SourcePath -Recurse -Force | 
    ForEach-Object -Process {
        Copy-Item -LiteralPath $_.FullName -Destination $TargetPath -Force
        Start-Sleep -Seconds 10
    }

The purpose is to get the files processed one after another using a loop in order to place our Start-Sleep after the file has been copied.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.