小编Eri*_*oso的帖子

用于根据修改日期复制文件的 Powershell 脚本,以从远程位置检查最新文件

我是 powershell 脚本的新手,我无法弄清楚为什么我的脚本会复制所有文件,并且似乎没有检查日期,然后无论如何都会复制所有文件。我也试图按天和分钟完成,但我不太确定如何做到这一点。任何帮助都会很棒!

see my script below.

$RemotePath = "\\eb-pc\E$\testlocation\*.txt"
$LocalPath = "C:\testlocation"
$Max_days = "-1"
#Max_mins = "-5"
$Curr_date = get-date

#Checking date and then copying file from RemotePath to LocalPath
Foreach($file in (Get-ChildItem $RemotePath))
{
    if($file.LastWriteTime -gt ($Curr_date).adddays($Max_days))
    {
        Copy-Item -Path $file.fullname -Destination $LocalPath
        #Move-Item -Path $file.fullname -Destination $LocalPath
    }

}
Run Code Online (Sandbox Code Playgroud)

powershell datetime copy

5
推荐指数
1
解决办法
3万
查看次数

标签 统计

copy ×1

datetime ×1

powershell ×1