1

I have a script that generates PDF reports using a command line application.

Here's the script in batch form (dates are variables):

QsrCrExport.exe -f"C:\SMTP\Reports\Speed of Service Summary" -o"C:\SMTP\Daily_Archive\SpeedofService.pdf" -a"Date:%one%,%one%" -epdf

I'm trying to implement the above into Powershell using start-process with arguments but cannot seem to get the arguments to correctly work

$crexport = "C:\Program Files (x86)\ReportViewer\Bin\QsrCrExport.exe";
$arguments = '-f"C:\ProgramData\ReportViewer\Reports\Speed of Service Summary" -o"C:\SMTP\Generated\SpeedofService.pdf" -a"Date:$reportdate1,$reportdate2" -epdf'
Start-Process $crexport $arguments -Wait;

I know this won't work wrapped in single-quotes as the variables wont be replaced with the value, however if I remove all the double quotes within the arguments and wrap the whole line in double quotes it still won't work.

I'm pretty new to powershell so apologies if this is something really straight forward.

user6808274
  • 33
  • 2
  • 7
  • http://stackoverflow.com/questions/38900961/passing-variable-arguments-using-powershells-start-process-cmdlet. This one is weak but the answer is correct. You need to __pass your arguments as an array__. Will flag as dupe if you agree. There are other answers about calling exe's but that is the best one I could fine for start-process that wasnt buried. – Matt Sep 28 '16 at 11:33

2 Answers2

1

You could use an argumentlist array:

Start-Process -FilePath '"C:\Program Files (x86)\ReportViewer\Bin\QsrCrExport.exe"' -ArgumentList @('-f"C:\ProgramData\ReportViewer\Reports\Speed of Service Summary"', '-o"C:\SMTP\Generated\SpeedofService.pdf"', '-a"Date:$reportdate1,$reportdate2"', '-epdf') -wait

That should work.

Asnivor
  • 266
  • 1
  • 8
0

The problem I see is that you have variables inside single quotes. I've switched the quotes so that everything inside the double quotes becomes expressed as an object instead of a dedicated string. Also by using the -f operator on a string inside the single quotes you can pass variables into the string, even inside single quotes.

$crexport = "C:\Program Files (x86)\ReportViewer\Bin\QsrCrExport.exe"
$arguments = ("-f 'C:\ProgramData\ReportViewer\Reports\Speed of Service Summary' -o 'C:\SMTP\Generated\SpeedofService.pdf' -a 'Date:{0},{1} -epdf'" -f $reportdate1, $reportdate2)
Start-Process $crexport $arguments -Wait