Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 将源文件夹中的所有文件和文件夹复制到具有特定名称的多个文件夹中_Powershell - Fatal编程技术网

Powershell 将源文件夹中的所有文件和文件夹复制到具有特定名称的多个文件夹中

Powershell 将源文件夹中的所有文件和文件夹复制到具有特定名称的多个文件夹中,powershell,Powershell,我有一个源文件夹(c:\test*),我希望将该文件夹复制到同一位置(c:\ResultAt)的所有文件夹中,但仅复制到该位置包含名称demo\u的文件夹中 我想我快到了,但我想我错过了一小部分 $destination = get-item -include demo_profit* -path C:\resultaat\* copy-item C:\test\* $destination -recurse -force 感谢您的帮助Get ChildItem的-Directory参数需要

我有一个源文件夹(c:\test*),我希望将该文件夹复制到同一位置(c:\ResultAt)的所有文件夹中,但仅复制到该位置包含名称demo\u的文件夹中

我想我快到了,但我想我错过了一小部分

$destination = get-item -include demo_profit* -path C:\resultaat\* 
copy-item C:\test\* $destination -recurse -force

感谢您的帮助

Get ChildItem的-Directory参数需要AFAIK PSv5

Get-ChildItem -Directory -Path 'C:\resultaat\' | ForEach-Object{
  if (Test-Path (Join-Path $_.FullName 'demo_profit')){
    Copy-Item C:\test\* $_.FullName -recurse -force
  }

因此,不清楚您是要将文件复制到包含名为demo_-price的项目的文件夹中,还是复制到名为demo_-price的文件夹中。第二个很简单,因此我将从这里开始:

Get-ChildItem C:\resultaat\* -Directory | 
    Where{$_.Name -match 'demo_profit'} | 
    ForEach{ Copy-Item C:\test\* -dest $_.FullName -recurse -force }
在c:\ResultAt中查找名称中包含“demo\u price”的任何文件夹,并将所需的文件/文件夹复制到该文件夹中。示例:C:\ResultAt\Folder1\u demo\u Profile会将C:\temp中的所有文件复制到其中

如果您正在查找名为demo_profit的内容,并希望将文件复制到与该项目相同的文件夹中,则需要使用PSParentPath属性和一些通配符

Get-ChildItem c:\resultaat\*\*demo_profit*
此命令将查找路径为“C:\resultaat\Amazon\az\u demo\u profice”的文件或文件夹。然后,要将文件复制到包含PSParentPath属性的文件夹中,请执行以下操作:

Get-ChildItem c:\resultaat\*\*demo_profit* |
    Select -Expand PSParentPath -Unique
    ForEach{ Copy-Item C:\test\* -dest $_ -recurse -force }

我想你需要一个循环,因为有不止一个目的地。类似于第二行的
$destination | foreach对象{copy item c:\test\*$\uu-recurse-force}
在PowerShell v3.0中添加了
-Directory
开关。