2

尝试执行 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)

我的 TeamCity 日志显示来自脚本块中 write-host 调用的这些值......

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\\*
4

1 回答 1

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 
} 
于 2016-04-15T12:59:43.937 回答