Invoke-Expression: Positional parameter cannot be found that accepts argument /s

mcmattu picture mcmattu · Sep 6, 2013 · Viewed 14.6k times · Source

I have a .ps1 script which contains a line

Invoke-Expression -Command "C:\Builds\$BuildName /s /v`"/l*v c:\build_install.txt /qn`""<br/>

This is performing Silent installation of a product.

Now, if I try to run this command from Linux box through ssh it gives the following error:

Invoke-Expression : A positional parameter cannot be found that accepts argument '/s'.
At line:1 char:1
+ Invoke-Expression C:\NWTBuilds\Setup-NimbleNWT-x64.2.0.4.117.exe /s /v`/l*v c:\n ...
+ CategoryInfo          : InvalidArgument: (:) [Invoke-Expression], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.InvokeExpressionCommand

Do you have any suggestions on this? Do I need to provide any credentials?

So I have also tried the following options:

  1. Send the command through ssh or telnet powershell.exe -Command ...
  2. Call the powershell Script from ssh or telnet powershell.exe -File C:\Sample.ps1

However If I ran the same Sample.ps1 from windows Powershell, silent installation is done?

Answer

Simon Catlin picture Simon Catlin · Sep 6, 2013

Your /s is being interpreted as being part of your Invoke-Expression call. Can you try Invoke-Command, i.e.:

Invoke-Command { C:\Builds\$BuildName /s /v "/l*v c:\build_install.txt /qn" }