I currently don't get over this problem since a couple of hours, as I searched everywhere for a solution. I might don't understand the topic yet that nothing works for me.

I created with powershell a command which has to be executed on a remote computer. As for the sake of the demo, i was testing it locally first without success. This is the code and the error:

#Defining Date
$DateYesterday =  (Get-Date).adddays(-1)
$dateyesterdayformat = Get-Date $dateyesterday -UFormat %Y/%m/%d
$DateToday = (Get-Date -UFormat %Y/%m/%d)

#creating command
$command1 = &("C:\Program Files (x86)\CLITOOL\tool.exe display statistics " +  $dateyesterdayformat + " " + $DateToday + " *")

The Final String looks as follow and correct:

C:\Program Files (x86)\CLITOOL\tool.exe display statistics 2016/08/15 2016/08/16 *

While trying to execute this command on local server:


I get this error:

The term 'C:\Program Files (x86)\CLITOOL\tool.exe display statistics 2016/08/15 2016/08/16 *' is not recognized as the name of a cmdlet,     function, script fil
e, or operable program. Check the spelling of the name, or if a path was includ
ed, verify that the path is correct and try again.
At line:1 char:20
+ $command1 = & <<<< ("C:\Program Files (x86)\CLITOOL\tool.exe display statistics " +  $dateyesterdayformat + " " + $DateToday + " *")
+ CategoryInfo          : ObjectNotFound: (C:\Program File...15     2016/08/16
    *:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

I definitly see the problem but I have no clue how to resolve it. How can I create a command, where I can pass those Dates & strings as an argument and let them be called?

Thank you in advance!



You have to separate the .exe and the arguments as following:

#creating command
$command1 = & "C:\Program Files (x86)\CLITOOL\tool.exe" "display statistics $dateyesterdayformat $DateToday *"

This way PowerShell executes tool.exe and passes the arguments correct.

  • Hey, I get the following error while using your code: file userstatistics $dateyesterdayformat $DateToday * : Unexpected token 'file userstatistics $dateyesterdayformat $DateToday *' in expression or statement. + CategoryInfo : ParserError: (file userstatis...at $DateToday *:String) [], ParseException + FullyQualifiedErrorId : UnexpectedToken – maes Aug 17 '16 at 13:48
  • Hey maes, sorry I miscopied your code, you have to remove the parantheses. I edited my answer – MicroScripter Aug 17 '16 at 14:12
  • Perfect! Your command has only needed the following corrections to work properly: I deleted the quotes on "display statistics $dateyesterdayformat $DateToday *" Now it works! Thank you very much! – maes Aug 22 '16 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.