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.

1
  • stackoverflow.com/questions/38900961/…. 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. Commented Sep 28, 2016 at 11:33

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.