Luk*_*ett 5 powershell teamcity
由于缺少参数,以下命令行会导致我的脚本抛出.仅当-WebServerList参数包含用于表示数组的括号时才会出现此问题.
这是由TeamCity发起的,我假设它正在制作一个简单的Windows shell命令,因此它可能()由shell/Windows解释.
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -ExecutionPolicy ByPass -File E:\PowerShell\DeploySolution.ps1`
    -ProjectName Integro -BuildVersion "8.0.5 (build 27692) " -DeploymentType IIS`
    -WebServerList @("ws1", "ws2") -WebServerUserName TeamCityMSDeploy`
    -WebServerPassword yeahR1ght -WebPackagePath E:\WebDeployPackages\IntegroWebAPI_QA_MSDeploy_Package.zip`
    -WebServerDestination Integro-QA`
    -MSDeployPath "C:\Program Files\IIS\Microsoft Web Deploy V3"
Run Code Online (Sandbox Code Playgroud)
但是,我尝试过DOS逃避^(  ...  ^),但这没有用.从Windows调用PowerShell脚本一直都很辛苦,毕竟谁想做一个疯狂的事情呢?!
与此同时,我将更改我的脚本以在单个字符串中访问CSV并手动拆分,这样我就可以回家了,但是知道是否有正确的方法可以解决这个问题.
问题似乎是操作系统无法正确定义阵列配置。您可以使用 -Command 而不是 -File 来实现与您想要的类似的效果:
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -ExecutionPolicy ByPass `
-Command "& E:\PowerShell\DeploySolution.ps1 -ProjectName Integro`
-BuildVersion '8.0.5 (build 27692) ' -DeploymentType IIS  `
-WebServerList @('ws1', 'ws2') -WebServerUserName TeamCityMSDeploy`
-WebServerPassword yeahR1ght `
-WebPackagePath E:\WebDeployPackages\IntegroWebAPI_QA_MSDeploy_Package.zip `
-WebServerDestination Integro-QA `
-MSDeployPath 'C:\Program Files\IIS\Microsoft Web Deploy V3'"
Run Code Online (Sandbox Code Playgroud)
干杯,克里斯。
我冒昧地编辑了你的答案来演示结果,并证明它是有效的。
从 DOS 命令提示符处:
C:\>c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -ExecutionPolicy ByPass -File c:\DATA\Git\PowerShell\Test-PassingArray.ps1 -Array milk
milk
C:\>c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -ExecutionPolicy ByPass -File c:\DATA\Git\PowerShell\Test-PassingArray.ps1 -Array @("milk", "cheese")
@(milk,
C:\>c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -ExecutionPolicy ByPass -Command "& c:\DATA\Git\PowerShell\Test-PassingArray.ps1 -Array @("milk", "cheese")"
At line:1 char:61
+ & c:\DATA\Git\PowerShell\Test-PassingArray.ps1 -Array @(milk, cheese)
+                                                             ~
Missing argument in parameter list.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingArgument
C:\>c:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -NonInteractive -ExecutionPolicy ByPass -Command "& c:\DATA\Git\PowerShell\Test-PassingArray.ps1 -Array @('milk', 'cheese')"
milk
cheese
C:\>
Run Code Online (Sandbox Code Playgroud)
        |   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           2734 次  |  
        
|   最近记录:  |