How to run bat file through powershell script

I am trying to execute bat file on the server via powershell deployment script in the pripeline but getting below error

script: $out = Invoke-Expression -Command “$RemotePath/status.bat”

Error on jenkin console

The term ‘/status.bat’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check
14:23:28 the spelling of the name, or if a path was included, verify that the path is correct and try again.
14:23:28 + CategoryInfo : ObjectNotFound: (/status.bat:String) , CommandNotFoundException
14:23:28 + FullyQualifiedErrorId : CommandNotFoundException

The PowerShell variable $RemotePath is expanding to the empty string. If the status.bat file is not in the root directory of the current drive, then it won’t be found at that location. Check that the $RemotePath variable has the value that you expect.

It is there. I have checked

Welcome to this community @jenkinpipeline :wave:

Stupid question: are you sure about your use of /? Shouldn’t it be \?

I have tried both ways but was still getting the same error thats why posted my issue here.

1 Like

How do you set the variable? If it is an environment variable, then use $Env:RemotePath.

(You could use $out = & "$RemotePath/status.bat" instead of Invoke-Expression. That’s not the problem, though.)