Jump to content

Hi all,

I'm experiencing an issue with Powershell passing trailing spaces within arguments and I'm quite restricted on what I can do due to contractual agreements. Is there a way to resolve this?
 

Input:

Powershell Start-Process 'C:\Program Files\Folder\program.exe' -Verb runAs -ArgumentList @('"parameter with spaces"', '-minimize')

Expected Passed Parameters:

  • "parameter with spaces"
  • "-minimize"

Actual Passed Parameters:

  • "parameter with spaces "
  • "-minimize "

Limitations

  • Program.exe must be ran from a program already running as admin (in this case powershell)
  • Not allowed to change default Execution Policy away from Restricted. So no Powershell scripts
  • Not allowed to install/execute external programs
  • Works if made into a shortcut (.lnk) on the Desktop

Any advice would be appreciated. Thanks in advance

PLEASE QUOTE ME IF YOU ARE REPLYING TO ME

Desktop Build: Ryzen 7 2700X @ 4.0GHz, AsRock Fatal1ty X370 Professional Gaming, 48GB Corsair DDR4 @ 3000MHz, RX5700 XT 8GB Sapphire Nitro+, Benq XL2730 1440p 144Hz FS

42U Server Rack: ISP Modem + UDM-SE + APC 3kVA UPS + 3x Dell Precision 5820 + TBD

Retro Build: Intel Pentium III @ 500 MHz, Dell Optiplex G1 Full AT Tower, 768MB SDRAM @ 133MHz, Integrated Graphics, Generic 1024x768 60Hz Monitor


 

Link to comment
https://linustechtips.com/topic/938871-start-process-passing-trailing-spaces/
Share on other sites

Link to post
Share on other sites

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/start-process?view=powershell-6#examples

 

Check example 7. You don't appear to be using the right syntax for -ArgumentList.

Start-Process -FilePath "$env:comspec" -ArgumentList "/c dir `"%systemdrive%\program files`""

OR

Start-Process -FilePath "$env:comspec" -ArgumentList "/c","dir","`"%systemdrive%\program files`""

 

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×