troubleshooting Question

Powershell copy file and show copy progress.

Avatar of Benjosp
Benjosp asked on
3 Comments1 Solution8072 ViewsLast Modified:
I am writing a script to copy big files from the C: to F: (external USB drive) the scrip is working fine but I would like to see a copy progress report on each file that is being copied so I know the job is not frozen. Is there a way to see that?

foreach($folder in (Get-ChildItem f:\backups)){ #Finds all forlders on f:\backups

#Counts the number of VBK files on the folder
$numFiles = (Get-ChildItem f:\backups\$folder -Recurse -Include "*.vbk").Count

#If the number of files > 1 then delete the files if not nothing to delete
If ($numFiles -gt 1)

    Write-Host 'Deleting VBN file on ' $folder
    Get-ChildItem f:\backups\$folder -Recurse -Include "*.vbm" | Remove-Item -Force
    Write-Host 'VBN file succesfully deleted on ' $folder
    Write-Host 'Deleting VBK file on ' $folder
    Get-ChildItem f:\backups\$folder -Recurse -Include "*.vbk" | Sort-Object lastwritetime | Select-Object -first 1 | remove-item -force
    Write-Host 'VBK file succesfully deleted on ' $folder
else {
        Write-Host "Only one file so nothing was deleted"

#Coping files to the F Drive
Write-Host "coping files to F...."

#Finds all folders in e:\backups
foreach($folder in (Get-ChildItem e:\backups)){

#Copies the VBN file
Write-Host 'Coping VBN file to ' $folder
Get-ChildItem e:\backups\$folder -Recurse -Include "*.vbm" | Copy-Item -Destination F:\backups\$folder
Write-Host 'VBN file succesfully copied to ' $folder

#Copies the VBK file
Write-Host 'Coping VBK file to ' $folder
Get-ChildItem e:\backups\$folder -Recurse -Include "*.vbk" | sort-object lastwritetime | Select-Object -last 1 | Copy-Item -Destination F:\backups\$folder
Write-Host 'VBK file succesfully copied to ' $folder

Write-Host 'All Done ' 

Open in new window

Meir Rivkin
Full stack Software Engineer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros