powershell Copy-Item路径

时间:2016-04-15 12:39:48

标签: powershell copy-item

尝试执行PowerShell脚本时,我从TeamCity收到以下错误。

Illegal characters in path.
     + CategoryInfo          : NotSpecified: (:) [Copy-Item], ArgumentException
     + FullyQualifiedErrorId : System.ArgumentException,Microsoft.PowerShell.Co 
    mmands.CopyItemCommand

下面是我正在调用的脚本块......

$xcopyFolderBlock = 
{ 
 $destFolder    = ($args[0] | out-string)
 $sourceFolder  = $args[1]

 # See what value was passed in to the script block
 write-host "destFolder inside xcopyFolder code block: " $destFolder
 write-host "sourceFolder inside xcopyFolder code block: " $sourceFolder

 Copy-Item $sourceFolder $destFolder -force -recurse -verbose 
} 

这就是我所说的......

Invoke-Command -ComputerName $web1Name -ScriptBlock $xcopyFolderBlock -ArgumentList(, $web1FolderServices, $nasFolderServices)

MY TeamCity日志显示脚本块中写入主机调用的这些值...

destFolder inside xcopyFolder code block:  \\\s1-bridge-web1\BridgeWebServices\Prod\MileageCalculator\v1.1.31\Services

sourceFolder inside xcopyFolder code block:  \\\s1-nas-1\software_dev\build\Prod\build_user\MileageCalculator\Services\\*

1 个答案:

答案 0 :(得分:0)

好的,我已经明白了。问题在于您在参数列表中的昏迷,这里:

-ArgumentList(, $web1FolderServices, $nasFolderServices)

因为你必须这样做:

($args[0] | out-string)

因此,如果您这样做,它将起作用:

Invoke-Command -ComputerName $web1Name -ScriptBlock $xcopyFolderBlock -ArgumentList($web1FolderServices, $nasFolderServices)

而且:

$xcopyFolderBlock = 
{ 
 $destFolder    = $args[0]
 $sourceFolder  = $args[1]

 # See what value was passed in to the script block
 write-host "destFolder inside xcopyFolder code block: " $destFolder
 write-host "sourceFolder inside xcopyFolder code block: " $sourceFolder

 Copy-Item $sourceFolder $destFolder -force -recurse -verbose 
}