我是 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)