Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 212
mcmattu Avatar asked Oct 03 '22 01:10

mcmattu


2 Answers

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" }
like image 52
Simon Catlin Avatar answered Oct 13 '22 10:10

Simon Catlin


The error message indicates that PowerShell is trying to parse /s as the name of a parameter of Invoke-Expression rather than as part of the argument supplied to -Command, which it would not do if the /s were part of the string. This implies that the string is being terminated just before that. Check the value of $BuildName, it probably contains something that terminates the string. I'm not quite sure what that might be, because a pair of double quotes within the variable value shouldn't have that effect. At least it wouldn't at a PowerShell prompt. Maybe the ssh client is interpreting what you're typing in some way that terminates the string before /s?

In any case, I'd be willing to bet money that the answer lies in the value of $BuildName, because logically the error indicates that the string argument to -Command terminates at that point.

like image 20
Adi Inbar Avatar answered Oct 13 '22 11:10

Adi Inbar