Ниже почти работает, но я упускаю что-то очевидное, в папке OURCE SOURCE у меня есть подпапка с именем Archive
.Однако, когда я запускаю код, кажется, что он не создает единственную папку ODS в целевой папке ODS, но ни одно из хранилищ CSV-файлов в папке не является копией, я ошибочно предположил, что -Filter обеспечит копирование только CSV-файлов..
## The location/filename where the Logs will be stored
$varfullpath = "C:\Users\Simon.Evans\Documents\ReferenceData__logfile.txt"
## The location/filename of the Source to copy from
$sourceDirectory = "C:\Users\Simon.Evans\Documents\Source Data\ODS\"
## The location/filename of the Destination to copy to
$destinationDirectory = "I:\Dev\BI\Projects\Powershell\Test Area\Source Data\ODS\"
## Attempts to copy a file fron Source to Destination and record the event, if the Copy-item fails the script is halted and the error messages are captured in the Log
## Possibly only 1 error is needed and or applicable, so remove as necessary.
try{
Copy-item -Force -Verbose $sourceDirectory -Filter ".csv" -Recurse -Destination $destinationDirectory -ErrorAction Stop
Write-Log -Message "Copy from $sourceDirectory to $destinationDirectory suceeded" -path $varfullpath
}
catch{
$Error[0] | Write-Log -path $varfullpath
Write-log -Message "Copy from $sourceDirectory to $destinationDirectory Failed" -Level Error -path $varfullpath
}
Start-Process notepad $varfullpath ## Opens the file immediately for review