重复的命令行参数

时间:2014-07-11 19:21:05

标签: powershell appfabric dsc

我收到一条错误消息,说我有一个重复的命令行参数......任何人都知道为什么会发生这种情况以及解决方法是什么?

enter image description here

$fileServer = 'server.contoso.local'
$MediaPath = "\\$fileServer\Deployment\Software\AppFabric\"
$MediaName = "WindowsServerAppFabricSetup_x64_6.1.exe"


$cmd = Join-Path $MediaPath -ChildPath $MediaName
$cmd += " /install CachingService , CacheClient , CacheAdmin /SkipUpdates /logfile "
$cmd += " F:\Logs\AppFabric\AppFabricInstallLog.txt "
Invoke-Expression -Command $cmd

以下是$ cmd的输出:

\\server.contoso.local\Deployment\Software\AppFabric\WindowsServerAppFabricSetup_x64_6.1.exe /i CachingService , CacheClient , CacheAdmin /SkipUpdates /logfile  F:\Logs\AppFabric\AppFabric\InstallLog.txt 

enter image description here

我已将其缩小到安装程序后调用的参数。 " CachingService,CacheClient,CacheAdmin"。如果我删除" CachingService,CacheClient,CacheAdmin"

,其他一切都有效

要添加的另一个注意事项...如果我在CMD.exe中运行这个完全相同的命令,它将正常工作。但是,我的任务是使用DSC(期望状态配置)在PowerShell中自动化

2 个答案:

答案 0 :(得分:4)

如果我通过echoargs.exe(PowerShell社区扩展中的实用程序)运行命令,我看到删除了逗号:

C:\PS> echoargs /i CachingService , CacheClient , CacheAdmin /SkipUpdates /logfile  F:\Logs\AppFabric\AppFabric\InstallLog.txt
Arg 0 is </i>
Arg 1 is <CachingService>
Arg 2 is <CacheClient>
Arg 3 is <CacheAdmin>
Arg 4 is </SkipUpdates>
Arg 5 is </logfile>
Arg 6 is <F:\Logs\AppFabric\AppFabric\InstallLog.txt>

Command line:
"C:\Program Files (x86)\PowerShell Community Extensions\Pscx3\Pscx\Apps\EchoArgs.exe"  /i CachingService CacheClient CacheAdmin /SkipUpdates /logfile F:\Logs\AppFabric\AppFabric\InstallLog.txt

如果您使用的是PowerShell V3或更高版本,请使用 - %将PowerShell置于简化(哑)参数解析模式,例如:

$cmd += " --% /install CachingService , CacheClient , CacheAdmin /SkipUpdates /logfile "

社区扩展的链接是http://pscx.codeplex.com。如果您正在尝试使用PowerShell 5.0预览版,则可以从PSGet库中安装它。

答案 1 :(得分:2)

要解决安装SharePoint 2016或2013的先决条件的问题,我使用以下脚本来绕过上述重复命令错误(在Windows 2012 R2中)

C:\>.\WindowsServerAppFabricSetup_x64.exe/i CacheClient","CachingService","CacheAdmin /gac