7

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?

Ansgar Wiechers
  • 193,178
  • 25
  • 254
  • 328
mcmattu
  • 101
  • 1
  • 2
  • 5

2 Answers2

4

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" }
Simon Catlin
  • 2,141
  • 1
  • 13
  • 15
  • I tried the above command it did not worked. I even tried the following option Invoke-Command -ScriptBlock { "C:\Builds\$BuildName /s /v'`/l*v c:\build_install.txt /qn`""} – mcmattu Sep 06 '13 at 21:39
1

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.

Adi Inbar
  • 12,097
  • 13
  • 56
  • 69
  • Thanks Adi, the Build Name is "mcmattu-2.0.0.1.exe". the thing is it is working if I get rid of Powershell altogether and let it run on default cmd prompt. – mcmattu Sep 06 '13 at 23:21
  • Can you show the code that assigns **$BuildName**? There *has* to be something in there that terminates the string (maybe some nonprinting character at the end?), because what the error is telling you is that the string is being terminated at that point, and `/s` is parsed as an argument to **iex**. – Adi Inbar Sep 15 '13 at 21:30
  • $BuildName = "Windows-NNN-Setup-x64.2.12.3.109.exe" – mcmattu Sep 16 '13 at 22:23
  • I'm confused. You said above that Build Name is "mcmattu-2.0.0.1.exe", but now you're saying that you're assigning "Windows-NNN-Setup-x64.2.12.3.109.exe" to **$BuildName**. Which is it? Also...try `$test = "C:\Builds\$BuildName /s /v\`"/l*v c:\build_install.txt /qn\`""; Write-Host $test` and see what you get back. – Adi Inbar Sep 16 '13 at 22:37