У меня есть скрипт, который должен скопировать список файлов в разные каталоги и местоположения на целевых серверах.
Я смог понять, что мне нужно создать CSV-файл следующим образом:
Мне нужно понять от вас, как сделать файлы из исходного местоположения в соседний файл в целевом местоположении. Есть идеи?
Мой код выглядит так:
# customize log file
$date = (Get-Date -Format d).ToString() | foreach {$_ -replace "/", "_"}
$time = (Get-Date)
$scriptDir = "D:\Scripts\ServerBuildToolkitT1\SingleFileUpfate\"
$logDir = "D:\Scripts\ServerBuildToolkitT1\Logs\SingleFileUpfate\"
$logFileName = "SingleFileUpfate $date.log"
$sources = @()
$destinsyions = @()
function CSV {
Import-Csv D:\Scripts_PS\SD.csv | ForEach-Object {
$sources += $_."Source Location"
$destinations += $_."Destination Location"
}
}
# this file contains the list of destination server that you want copy
# file/folder to
$computers = Get-Content "D:\Scripts_PS\ServerList.txt"
function main
{
foreach ($computer in $computers) {
foreach ($destination in $destinations) {
Write-Output "$([DateTime]::Now) Copying files update to $computer now" |
Out-File -FilePath "$logDir\$logFileName" -Append
Copy-Item $sources -Destination "\\$computer\$destination" -Force -Recurse -Verbose:$false
}
}
}
csv
main
Write-Output "$([DateTime]::Now) the operation SingleFileUpdate completed successefully" |
Out-File -FilePath "$logDir\$logFileName" -Append
Я обновил скрипт (как показано выше) и теперь получаю следующую ОШИБКУ
«ПРЕДУПРЕЖДЕНИЕ. Один или несколько заголовков не указаны. Вместо пропущенных заголовков используются имена по умолчанию, начинающиеся с« H »."