powershell - Copy-item 脚本的问题
问题描述
我有一个脚本需要将文件列表复制到目标服务器上的 ceraitn 目录和位置。我能够理解我需要创建一个 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”开头的默认名称代替任何丢失的标题。”
解决方案
推荐阅读
- c# - 当对象的默认构造函数不为空时创建假失败
- html - 如何减少标签和输入字段之间的差距
- amazon-web-services - 内存存储 (Elasticache) 与持久数据存储 (Dynamodb) 之间的读/写延迟比较(高级数字)
- c# - 使用相同的表单 .net 身份注册多个用户
- python - 为什么我的查询不起作用?'异常值:不能将 QuerySet 用于“对话”:将 QuerySet 用于“配置文件”'
- python - Pandas DataFrame Groupby:如何计算满足条件的分组行数
- pythonanywhere - 尝试从 PythonAnywhere 将一些 python 脚本下载到我的计算机,但它一直打开另一个浏览器选项卡
- r - mutate_at() 重命名多个变量而不改变原始列
- python - 字典值打印出不寻常/奇怪的数字
- python - 如果找到多个匹配项,如何通过读取行来查找匹配项并将值添加到单独的变量中。= 使用 Python