# Running a powershell script from Ignition

**URL:** <https://forum.inductiveautomation.com/t/running-a-powershell-script-from-ignition/81951>\
**Category:** Ignition\
**Created:** [November 15, 2023, 7:37pm UTC](https://forum.inductiveautomation.com/t/running-a-powershell-script-from-ignition/81951 "2023-11-15T19:37:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Melvin\_Cancino](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@Melvin\_Cancino](https://forum.inductiveautomation.com/u/Melvin_Cancino)\
**Post date:** [November 15, 2023, 7:37pm UTC](https://forum.inductiveautomation.com/t/running-a-powershell-script-from-ignition/81951/1 "2023-11-15T19:37:13Z")

</div>

Hi, I'm trying to run a simple powershell script in ignition. I'm not getting any errors, so I don't know what is wrong with it. I have 2 scripts. On the second script, I'm getting error

"Process[pid=33536, exitValue="not exited"]"

Each time I try running that script the pid changes

```auto
system.util.execute([
"C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", 
"-File", 
"C:\\Users\\user\\Desktop\\writeName.ps1"
])

```

```auto
# Import the necessary Ignition modules
from java.lang import Runtime

# Define the path to your PowerShell script
powershell_script_path = "C:\Users\user\Desktop\writeName.ps1"

# Run the PowerShell script using the Windows PowerShell executable
Runtime.getRuntime().exec(["powershell", "-ExecutionPolicy", "Bypass", "-File", powershell_script_path])

```

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [November 15, 2023, 7:39pm UTC](https://forum.inductiveautomation.com/t/running-a-powershell-script-from-ignition/81951/2 "2023-11-15T19:39:05Z")

</div>

What is the execution environment of this? Perspective? Vision? A gateway script?

---

<div class="post-metadata">

**Author:** ![Melvin\_Cancino](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@Melvin\_Cancino](https://forum.inductiveautomation.com/u/Melvin_Cancino)\
**Post date:** [November 15, 2023, 7:39pm UTC](https://forum.inductiveautomation.com/t/running-a-powershell-script-from-ignition/81951/3 "2023-11-15T19:39:49Z")

</div>

This is on Vision. I'm trying to set this script up with a button

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [November 15, 2023, 7:40pm UTC](https://forum.inductiveautomation.com/t/running-a-powershell-script-from-ignition/81951/4 "2023-11-15T19:40:11Z")

</div>

The computer that is running the vision client needs to have this file `C:\Users\user\Desktop\writeName.ps1` - does it?

As well as that same path for powershell but that's a bit more uniform.

---

<div class="post-metadata">

**Author:** ![Melvin\_Cancino](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@Melvin\_Cancino](https://forum.inductiveautomation.com/u/Melvin_Cancino)\
**Post date:** [November 15, 2023, 7:41pm UTC](https://forum.inductiveautomation.com/t/running-a-powershell-script-from-ignition/81951/5 "2023-11-15T19:41:36Z")

</div>

Yes, that file is available on the desktop where I am running vision client. It needs to be there

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [November 18, 2023, 9:58pm UTC](https://forum.inductiveautomation.com/t/running-a-powershell-script-from-ignition/81951/6 "2023-11-18T21:58:01Z")

</div>

> [@Melvin\_Cancino](#):
>
> "Process[pid=33536, exitValue="not exited"]"

Looking at [the docs](https://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Process.html), I see a couple of methods that look useful. If this is a long running script, perhaps try using `waitFor()` to give the script more time to complete, and if the script doesn't complete for some reason, handle it with the `destroy()` method.
