以下脚本将文件从一个位置复制到另一位置,实际上,将有很多文件要复制。在运行复制命令时显示其进度的最佳方法是什么?也就是说,如果它仍在继续运行,则说明它已经失败或完成。
$from = "C:\Sites\T"
$to = "C:\Customer\"
$exclude = @("Aeromark")
$excludeMatch = @("Aeromark")
$StartDate = (Get-Date).AddYears(-2)
$EndDate = Get-Date
[regex]$excludeMatchRegEx = ‘(?i)‘ + (($excludeMatch | foreach {[regex]::Escape($_)}) –join “|”) + ‘’
Get-ChildItem -Path $from -Recurse -Exclude $exclude | where {
$excludeMatch -eq $null -or
$_.FullName.Replace($from, "") -notmatch $excludeMatchRegEx -and
($_.CreationTime.Date -ge $StartDate.Date) -and
($_.CreationTime.Date -le $EndDate.Date)
} | Copy-Item -Destination {
if ($_.PSIsContainer) {
Join-Path $to $_.Parent.FullName.Substring($from.Length)
} else {
Join-Path $to $_.FullName.Substring($from.Length)
}
} -Force -Exclude $exclude -Verbose *> c:\temp\log_sites_customer_excluding_aeromark_copy.txt