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:
powershell.exe -Command ...
powershell.exe -File C:\Sample.ps1
However If I ran the same Sample.ps1
from windows Powershell, silent installation is done?
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" }
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With