无法识别的参数'ComputerName'。所有参数必须以“-”开头

时间:2019-04-14 19:08:58

标签: powershell web-deployment webdeploy

msdeploy.exe : Error: Unrecognized argument 'ComputerName='https://QMX-STG-WEB2:8172/msdeploy.axd''. All arguments must begin with "-".
At C:\Users\scheluka\Desktop\copy.ps1:11 char:1
+ & 'C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe' `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (Error: Unrecogn...begin with "-".:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

Error count: 1.
& 'C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe' `
-source:iisApp=`'C:\Work\US17830_Latest\webapps\orchestration_snwatchlist\apps`' `
-dest:iisApp=`'Default Web Site/test/vmes`' ,ComputerName=`'https://QMX-STG-WEB2:8172/msdeploy.axd`',UserName=$username,Password=$password,IncludeAcls=`'False`',AuthType=`'Basic`' `
-verb:sync `
-verbose `
-disableLink:AppPoolExtension `
-disableLink:ContentExtension `
-disableLink:CertificateExtension `
-allowUntrusted `
-retryAttempts=2 `
-skip:objectName=filePath,absolutePath=.bin

1 个答案:

答案 0 :(得分:0)

过度使用反引号。 与其他操作字符一样,逗号在PowerShell中是自然中断。

如果您追求人类可读性,并且希望避免使用那些冗长的语句(我理解-但是在某些情况下它们是不可避免的),那么您可以尝试以下选项...

# 1 
& 'C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe' "-source:iisApp='C:\Work\US17830_Latest\webapps\orchestration_snwatchlist\apps' -dest:iisApp='Default Web Site/test/vmes',
ComputerName='https://QMX-STG-WEB2:8172/msdeploy.axd',
UserName=$username,
Password=$password,
IncludeAcls='False',
AuthType='Basic' -verb:sync -verbose -disableLink:AppPoolExtension -disableLink:ContentExtension -disableLink:CertificateExtension -allowUntrusted -retryAttempts=2 -skip:objectName=filePath,
absolutePath=.bin"



# 2
$Arguments = "-source:iisApp='C:\Work\US17830_Latest\webapps\orchestration_snwatchlist\apps' 
-dest:iisApp='Default Web Site/test/vmes',
ComputerName='https://QMX-STG-WEB2:8172/msdeploy.axd',
UserName=$username,
Password=$password,
IncludeAcls='False',
AuthType='Basic' 
-verb:sync 
-verbose 
-disableLink:AppPoolExtension 
-disableLink:ContentExtension 
-disableLink:CertificateExtension 
-allowUntrusted 
-retryAttempts=2 
-skip:objectName=filePath,absolutePath=.bin" 

# If you view the variable content it will show as it looks, but it's really a single line
$Arguments
$Arguments.Count
$Arguments.Length


& 'C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe' """$Arguments"""


# 3 - if the exe does not see the above as a single line. You can make it one on the fly
$Arguments = "-source:iisApp='C:\Work\US17830_Latest\webapps\orchestration_snwatchlist\apps' 
-dest:iisApp='Default Web Site/test/vmes',
ComputerName='https://QMX-STG-WEB2:8172/msdeploy.axd',
UserName=$username,
Password=$password,
IncludeAcls='False',
AuthType='Basic' 
-verb:sync 
-verbose 
-disableLink:AppPoolExtension 
-disableLink:ContentExtension 
-disableLink:CertificateExtension 
-allowUntrusted 
-retryAttempts=2 
-skip:objectName=filePath,absolutePath=.bin" -replace "`n|`r"

# this makes sure it see a line
"""$Arguments""" | clip # Just paste in to notepad to see the line. Well as long as notepad is not set to word wrap

& 'C:\Program Files\IIS\Microsoft Web Deploy V3\msdeploy.exe' """$Arguments"""