计算文件夹大小、拷贝文件显示进度
计算文件夹大小
(get-childitem -path $folder -recurse| measure-object -property length -sum).sum/1mb
#拷贝文件提示进度(脚本只对零散文件有效,如果有大型文件的话,进度显示不正确)
$folder = "D:\Temp_del"
$des = "d:\test"
$p=0
$sizes = (get-childitem -path $folder -recurse| measure-object -property length -sum).sum/1kb
#$copyjob = start-job -ScriptBlock {copy-item D:\ISO\aa d:\test -Recurse -force}
$copyjob = start-job -ScriptBlock {param($folder,$des);copy-item $folder $des -Recurse -force} -ArgumentList $folder,$des
do {
$sizesd = (get-childitem -path $des -recurse| measure-object -property length -sum).sum/1kb
start-sleep -Milliseconds 10
$p = $sizesd/$sizes*100
$n = $sizesd/1MB
write-progress -Activity "进度显示" -status "已复制 $n MB , $p %" -PercentComplete $p
$jobstate = (get-job -name $copyjob.name).state
}
until ($jobstate -eq "Completed")