我有远程服务器,每天将上传一个文件。不知道文件什么时候上传。我需要将此文件复制到另一台服务器进行处理,并且每个文件只需要执行一次(每天一次)。当文件上传到远程服务器时,我需要在一个小时内复制它,所以我必须每小时至少运行一次这个脚本。我正在使用这个脚本:
# Get yesterday date
$date = (Get-Date).Adddays(-1) | Get-Date -Format yyyyMMdd
$check = ""
$check = Get-Content c:\checkiftransfered.txt
# Test if file checkiftransfered.txt contains True or False. If it contains True, file for this day was already copyied
if ($check -ne "True") {
#Test if file exists - it has specific name and yesterday date
if(Test-Path \\remoteserver\folder\abc_$date.xls) {
Copy-Item \\remoteserver\folder\abc_$date.xls \\remoteserver2\folder\abc_$date.xls
# Write down information that file was already copyied
$check = "True" | Out-File c:\checkiftransfered.txt
} else { Write-Host "File has not been uploaded."}
} else { Write-Host "File has been copyied."}
# + I will need another script that will delete the checkiftransfered.txt at 0:00
我认为它会正常工作,但我正在寻找更优雅的解决方案 - 如何解决它的最佳方法。谢谢