Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.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_Concatenation_Filepath - Fatal编程技术网

解决在powershell中将目标参数作为脚本块写入的问题

解决在powershell中将目标参数作为脚本块写入的问题,powershell,concatenation,filepath,Powershell,Concatenation,Filepath,我的组织在网络上的不同文件夹中有很多图片文件。 我一直在按项目文件夹将它们合并到“PictureLibrary”文件夹中。 因为在这些项目文件夹中除了图片文件还有其他文件,所以我不能只移动整个文件夹。 我一直在尝试下面的代码: ($Images = gci "Z:\DivisionFolder" -Recurse -file -Include "*.jpg") | Foreach-object { copy-Item $_.DirectoryName -D

我的组织在网络上的不同文件夹中有很多图片文件。 我一直在按项目文件夹将它们合并到“PictureLibrary”文件夹中。 因为在这些项目文件夹中除了图片文件还有其他文件,所以我不能只移动整个文件夹。 我一直在尝试下面的代码:

    ($Images = gci "Z:\DivisionFolder" -Recurse -file -Include "*.jpg") |
        Foreach-object {
        copy-Item $_.DirectoryName -Destination "Z:\DivisionFolder\PictureLibrary"
        }
$a=0
For ($a; $a -lt $Images.count; $a++){
    move-item $Images[$a].fullname -Destination {join-path -Path "D:\(1) PROJECTS & PORTFOLIOS\PictureLibrary" -ChildPath $Images[$a].Directoryname}
    }
我尝试过各种格式,但出现了这个错误

复制项:无法计算参数“Destination”,因为其 参数被指定为脚本块,并且没有输入。A. 没有输入,无法计算脚本块

如果不将目的地写为脚本块,我就无法理解如何编写它


任何帮助都将不胜感激

请尝试像这样传递destination参数:

-Destination $(. { script_block_body_here })

()。{}是点源运算符,$()是子表达式运算符。

尝试像这样传递目标参数:

-Destination $(. { script_block_body_here })
($RougePictures = Get-Childitem -Path "C:\" -recurse -file -Include "*.JPG")|
   Foreach-object {
        copy-Item $_.DirectoryName -Destination "C:\Folders\PictureLibrary"
    }
$MainFolders = get-childitem -Path "D:\(1) PROJECTS & PORTFOLIOS\PictureLibrary"       

$a=0
For ($a; $a -lt $MainFolders.count; $a++) {
    Foreach ($Rouge in $RougePictures){
        if ((compare-object (split-path $Rouge.directoryname -leaf) $MainFolders[$a] -IncludeEqual).sideindicator -eq '=='){
             move-item $Rouge.fullname -destination $MainFolders[$a].fullname 
         }
    }
}
()。{}是点源运算符,$()是子表达式运算符

($RougePictures = Get-Childitem -Path "C:\" -recurse -file -Include "*.JPG")|
   Foreach-object {
        copy-Item $_.DirectoryName -Destination "C:\Folders\PictureLibrary"
    }
$MainFolders = get-childitem -Path "D:\(1) PROJECTS & PORTFOLIOS\PictureLibrary"       

$a=0
For ($a; $a -lt $MainFolders.count; $a++) {
    Foreach ($Rouge in $RougePictures){
        if ((compare-object (split-path $Rouge.directoryname -leaf) $MainFolders[$a] -IncludeEqual).sideindicator -eq '=='){
             move-item $Rouge.fullname -destination $MainFolders[$a].fullname 
         }
    }
}
找到了将脚本块用作目标参数的变通方法。 使用
if((比较对象(分割路径$Rouge.directoryname-leaf)$MainFolders[$a]-IncludeEqual.sideindicator-eq'='))

复制文件夹后,
copy Item$\目录名-Destination“C:\folders\PictureLibrary”
以查找与图片所在文件夹相匹配的文件夹。如果找到匹配项,
“==”
移动项将移动这些文件。 希望这有帮助

找到了将脚本块用作目标参数的变通方法。 使用
if((比较对象(分割路径$Rouge.directoryname-leaf)$MainFolders[$a]-IncludeEqual.sideindicator-eq'='))

复制文件夹后,
copy Item$\目录名-Destination“C:\folders\PictureLibrary”
以查找与图片所在文件夹相匹配的文件夹。如果找到匹配项,
“==”
移动项将移动这些文件。
希望这有帮助。

您是否尝试将圆括号用于连接路径,而不是从中抛出脚本块错误的圆括号-Destination(join path…Directoryname)@ShamusBerube我做了,它没有给我相同的错误,但不幸的是它仍然不起作用。Scriptblock参数只能在管道中使用。您是否尝试使用圆括号代替花括号作为连接路径,而不是从中抛出脚本块错误-Destination(join path…Directoryname)@ShamusBerube我有,它没有给我相同的错误,但不幸的是它仍然不起作用。Scriptblock参数只能在管道中使用。谢谢你的回复。我不确定我的格式是否正确,我查阅了
Get Help“about\u Operators”
,据我所知,我得到了
-Destination$(..\MovePics.ps1{join path-path-path“D:\(1)PROJECTS&portfolions\PictureLibrary”-ChildPath$Images[$a].Directoryname})
它复制了文件夹(
the$\ Directoryname
)像以前一样,但陷入循环中,永远不会移动到
移动项
。有什么建议吗?谢谢你的回复。我不确定我的格式是否正确,我查阅了
Get Help“about\u Operators”
,据我所知,我得到了
-Destination$(..\MovePics.ps1{join path-path-path“D:\(1)PROJECTS&portfolions\PictureLibrary”-ChildPath$Images[$a].Directoryname})
它复制了文件夹(
the$\ Directoryname
)像以前一样,但陷入循环中,永远不会移动到
移动项
。有什么建议吗?