リモートサーバーがあり、1日に1つのファイルがアップロードされます。ファイルがいつアップロードされるかわかりません。このファイルを処理するために別のサーバーにコピーする必要があり、ファイルごとに1回だけ(1日1回)これを行う必要があります。ファイルをリモートサーバーにアップロードする場合、1時間以内にコピーする必要があるため、このスクリプトを少なくとも1時間に1回実行する必要があります。私はこのスクリプトを使用しています:
# 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
それはうまくいくと思いますが、私はもっとエレガントな解決策を探しています-それを解決するための最良の方法です。ありがとうございました