Starting exe - $env - Unexpected token

Works fine:

c:\r_sps\progs_common\PsExec64.exe -i -s "c:\temp\7z2201-x64.exe" "/S"

Throws ’ UnexpectedToken’ (Environment-variable _R_SPS is set to c:\r_sps):

$env:_R_SPS+"\"progs_common\PsExec64.exe -i -s "c:\temp\7z2201-x64.exe" "/S" 

Many thanks - Michael

Do you have an environment variable with the nacme “_R_SPS” in your system? Such a name would be quite unusual. :thinking:

What do you actually want to “express” with this?

Yes: _R_SPS is defined in my environment. The name is unusual intentionally in order to most probaly not conflict with other variables.

_R_SPS ist det to a certain directory and with $env:_R_SPS+"\"progs_common\PsExec64.exe I want to start PsEXEC64.exe stored in this directory. Most probably the problem is with the quoting (", ') of the parameters.

Michael
Michael

Hmmm … ok … so either you use

to concatenate the parts of a valid path beforehand and assign it to a variable you use later on. Or you use strings like this:

($env:_R_SPS + '\progs_common\PsExec64.exe')

May I ask why you’re using PsExec?

I use PSExec with SYSTEM-Permission (-s) in order to avoid UAC-problems and have a really silent installation .
I solved my problem in the meantime via:

   " $env:_R_SPS\progs_common\PsExec64.exe -i -s `"$installpath`" $app_Installationsparameter " | out-file -LiteralPath $batfile -Width 160 -Encoding ASCII -Force
   & $psexec $batfile | Out-Null

with installpath: Path to Install-exe and app_Installationsparameter = " /S" for silent install (in this case 7-Zip).
The background of my efforts: I want to create an easy-to-use, costless, automatic (therfore the request for silent installation) und secure (controlled by me via malware-scans etc.) Choloatey/nuget-alternative for installation / updating apllications basd on a JSON-control-file.

Thanks - Michael

But you need to run this script from an elevated PowerShell session anyway!? I’d recommend to make your code as simple as possible. The use of PsExec is very likely unnecessary.

For the vast majority of the tasks given you are not the very first one. You don’t have to re-invent the wheel again. Please use your prefered internet search engine and look for examples for tasks like this. There are frameworks out there specially made for this kind of tasks … for example …

Elevated is less then SYSTEM privilege: In order to avoid the UAC User Account Control inquiry on installation (real silent install) you need SYSTEM privilege. The onyl easy solution for this seems to be psexec(64).
Of cource I invested a lot of time in order to prohibit reinventing but on the other side gain trust in the solution. PowerShell App Deployment Toolkit (thanks for this hint) seems to be a great toolkit but needs a framework (for example for automatic and silent updates).
Michael

No. You do not.

You don’t need. But it would make your life easier and reduce the chance for errors or vulnerabilities a lot.

But at the end of the day you’re a grown up individual. You don’t need to follow the recommendations from others. You can make your own decisions and your own mistakes. :man_shrugging:t4:

No you do not: Please try (for example) install 7-Zip as administrator and you will encounter UAC User Account Control inquiry.

Michael

I do software deployments for more than 15 years now. It is part of my daily job.

If you see an UAC prompt trying to install any software product you’re doing it wrong.

I do it for 35 years (maybe that is the problem :slight_smile: )

Please see discussion in Technet which supports my experiences. Please be aware that 7-Zip for example has no certificate.

Michael

This discussion does not lead anywhere. And it is not a PowerShell topic anymore. You have your opinion and you’re allowed to.

Have a nice day.