# How to run bat file through powershell script

**URL:** <https://community.jenkins.io/t/how-to-run-bat-file-through-powershell-script/3070>\
**Category:** Ask a question\
**Created:** [July 18, 2022, 1:33pm UTC](https://community.jenkins.io/t/how-to-run-bat-file-through-powershell-script/3070 "2022-07-18T13:33:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jenkinpipeline](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@jenkinpipeline](https://community.jenkins.io/u/jenkinpipeline)\
**Post date:** [July 18, 2022, 1:33pm UTC](https://community.jenkins.io/t/how-to-run-bat-file-through-powershell-script/3070/1 "2022-07-18T13:33:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![MarkEWaite](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/markewaite/32/20_2.png) [@MarkEWaite](https://community.jenkins.io/u/MarkEWaite)\
**Post date:** [July 18, 2022, 4:42pm UTC](https://community.jenkins.io/t/how-to-run-bat-file-through-powershell-script/3070/2 "2022-07-18T16:42:13Z")

</div>

> [@jenkinpipeline](#):
>
> 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.

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.

---

<div class="post-metadata">

**Author:** ![jenkinpipeline](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@jenkinpipeline](https://community.jenkins.io/u/jenkinpipeline)\
**Post date:** [July 27, 2022, 12:25pm UTC](https://community.jenkins.io/t/how-to-run-bat-file-through-powershell-script/3070/3 "2022-07-27T12:25:12Z")

</div>

It is there. I have checked

---

<div class="post-metadata">

**Author:** ![poddingue](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/poddingue/32/985_2.png) [@poddingue](https://community.jenkins.io/u/poddingue)\
**Post date:** [July 29, 2022, 6:57am UTC](https://community.jenkins.io/t/how-to-run-bat-file-through-powershell-script/3070/4 "2022-07-29T06:57:19Z")

</div>

Welcome to this community @jenkinpipeline 👋

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

---

<div class="post-metadata">

**Author:** ![jenkinpipeline](https://avatars.discourse-cdn.com/v4/letter/j/7ea924/32.png) [@jenkinpipeline](https://community.jenkins.io/u/jenkinpipeline)\
**Post date:** [August 26, 2022, 10:50am UTC](https://community.jenkins.io/t/how-to-run-bat-file-through-powershell-script/3070/5 "2022-08-26T10:50:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kon](https://dub1.discourse-cdn.com/flex013/user_avatar/community.jenkins.io/kon/32/1197_2.png) [@kon](https://community.jenkins.io/u/kon)\
**Post date:** [August 26, 2022, 1:49pm UTC](https://community.jenkins.io/t/how-to-run-bat-file-through-powershell-script/3070/6 "2022-08-26T13:49:30Z")

</div>

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.)
