无法将文件夹内容从一台服务器复制到服务器列表 [英] Can’t copy folder content from one server to list of servers
问题描述
我正在尝试将一个包含 exe 和 msi 文件的文件夹从一台服务器复制到文本文件列表中的所有服务器.
I am trying to copy a folder full of exe and msi files from one server to all servers in the list in a text file.
到目前为止,我很幸运在目标服务器中复制或创建了一个空文件夹,但在源服务器上复制文件夹的内容时没有运气.有人可以帮助我实现这一目标吗?
So far I was lucky to copy or create a empty folder in the destination servers but no luck in copying the content of the folder on the source server. Can some one help me achieve this?
$comname = Get-Content -path 'H:\Installation Files\Patch Update files\server.txt'
Foreach ($value in $comname) {
$ss = "H:\Installation Files\Patch Update Files\Jun 2018"
If (Test-path $ss) {
$dest = "\\$value\H$\Install.*\Patch.*\Jun 2018"
If (Test-path $dest) {
Copy-Item -path $ss -destination $dest -force
}
Else {
Write-output "$dest does not exists"
}
}
Else {
Write-output "$ss does not exists"
}
}
有人可以帮助将源服务器文件夹中的所有内容/文件复制到目标服务器文件夹.我没有收到任何错误.该脚本运行良好,并在目标服务器上复制或创建一个空文件夹.如何将源服务器文件夹中的内容/文件复制到目标服务器?
Can someone help in copying all the contents/Files in the source server folder to destination server folder. I am not getting any error. The script runs fine and copies or create an empty folder on the destination server. How to get the contents/Files in the source server folder to copied to the destination server?
推荐答案
不能在目标文件夹路径上使用正则表达式.并且使用 -Recurse 解决了创建目标文件夹后复制文件夹内所有文件的问题.
Can’t use regex on Destination folder path. And use of -Recurse solved the problem of copying all the files in the folder after creating a destination folder.
Else {
New-Item -path $dest -type directory -force
Copy-Item -path $source -destination $dest -Recurse
}
这篇关于无法将文件夹内容从一台服务器复制到服务器列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!