首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将参数传递给Powershell

将参数传递给Powershell
EN

Stack Overflow用户
提问于 2012-07-23 23:29:38
回答 1查看 959关注 0票数 2

我有以下PS脚本:

代码语言:javascript
复制
function Install-BizTalkApplication
{
 param(
  [Parameter(Position=0,Mandatory=$true,HelpMessage="Msi file should be existing")]
  [ValidateScript({Test-Path $_})]
  [Alias("msi")]
  [string]$MsiFile,

  [Parameter(Position=1,HelpMessage="Path wherein the resource file will be installed")]
  [Alias("path")]
  [string]$ApplicationInstallPath,

  [Parameter(Position=2,Mandatory=$true,HelpMessage="Only valid parameters are Local,Dev,Test and Prod")]
  [Alias("env")]
  [ValidateSet("Local","Dev","Prod","Test")]
  [string]$Environment,

[bool]$BTDeployMgmtDB=$true,
  [bool]$SkipUndeploy=$true
  )

使用Powershell ISE,我尝试运行该脚本,传递3个参数,如下所示:

代码语言:javascript
复制
BTDF\Sources\Deployment\BuildAndDeploy.ps1 -msi "C:\Builds\1\CIDemo2\CIDemo2 BTDF\Sources\Deployment\bin\Debug\CIDemo-1.0.0.msi" -ApplicationInstallPath "c:\program files (x86)\CIDemo" -Environment "Dev"

但我得到以下错误:

代码语言:javascript
复制
The string starting:
At line:1 char:1
+  <<<< 'C:\Builds\1\CIDemo2\CIDemo2 BTDF\Sources\Deployment\BuildAndDeploy.ps1 -msi "C:\Builds\1\CIDemo2\CIDemo2 BTDF\Sources\Deployment\bin\Debug\CIDemo-1.0.0.msi" -ApplicationInstallPath "c:\program files
 (x86)\CIDemo" -Environment "Dev"
is missing the terminator: '.
At line:1 char:233

谁能解释一下我应该如何传递包含空格的参数?我试过用单引号,但没有用到joy。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-07-24 00:16:21

您的路径中有一个空格- C:\Builds\1\CIDemo2\CIDemo2 BTDF\Sources\Deployment\BuildAndDeploy.ps1

你必须引用它。

像这样运行它:

代码语言:javascript
复制
& 'C:\Builds\1\CIDemo2\CIDemo2 BTDF\Sources\Deployment\BuildAndDeploy.ps1' -msi "C:\Builds\1\CIDemo2\CIDemo2 BTDF\Sources\Deployment\bin\Debug\CIDemo-1.0.0.msi" -ApplicationInstallPath "c:\program files (x86)\CIDemo" -Environment "Dev"
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11615649

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档