【问题标题】:PowerShell Script to copy file to multiple folders listed in text or csv file用于将文件复制到文本或 csv 文件中列出的多个文件夹的 PowerShell 脚本
【发布时间】:2021-04-16 00:06:14
【问题描述】:

我想将一个文件复制到多个文件夹,文件夹列在一个文本文件中。新手到 PS,感谢帮助。我要复制的文件位于C:\Users\Desktop\Test\,但每次都会有不同的文件名。

foreach($folder in Get-Content "I:\foldername.txt")
{
  copy-item C:\Users\Desktop\Test\ -Destination \\servername\folder1\$Folder
}

我得到的错误是“复制项:找不到接受参数 '\Scott1' 的位置参数。”

【问题讨论】:

  • 那么问题是什么?您究竟需要什么帮助?
  • 脚本不工作,出现错误“复制项:找不到接受参数'\Scott1'的位置参数。”

标签: powershell file directory


【解决方案1】:

已经一个星期了,但我想我已经有了一些答案,您只需要更改路径和位置。

首先,将一个文件复制到多个文件夹,我所做的是使用文字路径(c:\users\blah\blah\content.txt 没有“”)制作一个文本文档,然后使用这个:

 $Folders = Get-Content "C:\Users\Andre\Desktop\Folder Names.txt"

 Foreach ($Folder in $Folders){
 Copy-Item "C:\Users\Andre\Downloads\test\Copying\File to copy.txt" -Destination 
 $Folder -Verbose}

然后我为多个文件复制到多个位置制作了这个。

$Folders = Get-Content "C:\Users\Andre\Desktop\Folder Names.txt"
Foreach ($Folder in $Folders){
Get-ChildItem -LiteralPath "C:\Users\Andre\Desktop\Copying" | Copy-Item -Destination 
$Folder -Force -Container}

【讨论】: