# Powershell script

**URL:** <https://forum.inductiveautomation.com/t/powershell-script/73793>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [May 16, 2023, 2:53pm UTC](https://forum.inductiveautomation.com/t/powershell-script/73793 "2023-05-16T14:53:32Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Muhammad\_Saim](https://avatars.discourse-cdn.com/v4/letter/m/7ab992/32.png) [@Muhammad\_Saim](https://forum.inductiveautomation.com/u/Muhammad_Saim)\
**Post date:** [May 16, 2023, 2:53pm UTC](https://forum.inductiveautomation.com/t/powershell-script/73793/1 "2023-05-16T14:53:32Z")

</div>

Hello for some reason bat scripts work but ps1 scripts don't. Is there something special that needs to be done for powershell scripts?

I have the below script running as a gateway update event script and the ps1 and bat files are located in the same location. The delete tag increments for bat but not ps1

````auto
import time
try:
	time.sleep(5)
#	gitEXE = "C:\\Program Files\\Inductive Automation\\Ignition\\data\\git-auto-commit.bat"
	gitEXE = "C:\\Program Files\\Inductive Automation\\Ignition\\data\\git-auto-commit.ps1"
	logger.warn(str(system.file.fileExists(gitEXE))) 
	system.util.execute([gitEXE])
	val = system.tag.readBlocking("[Ignition_Remote_IO_Gateway]aTestSharedFolder/delete")[0].value
	system.tag.writeBlocking("[Ignition_Remote_IO_Gateway]aTestSharedFolder/delete", val+1)
except Exception as e:
	logger.warn(str(e))```
````

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 16, 2023, 2:58pm UTC](https://forum.inductiveautomation.com/t/powershell-script/73793/2 "2023-05-16T14:58:50Z")

</div>

Do you get an error ?

---

<div class="post-metadata">

**Author:** ![Muhammad\_Saim](https://avatars.discourse-cdn.com/v4/letter/m/7ab992/32.png) [@Muhammad\_Saim](https://forum.inductiveautomation.com/u/Muhammad_Saim)\
**Post date:** [May 16, 2023, 7:45pm UTC](https://forum.inductiveautomation.com/t/powershell-script/73793/3 "2023-05-16T19:45:25Z")

</div>

Nothing shows up in the console log or the logger on the gateway page with the except statement.

---

<div class="post-metadata">

**Author:** ![kcollins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kcollins/32/19646_2.png) [@kcollins](https://forum.inductiveautomation.com/u/kcollins)\
**Post date:** [May 17, 2023, 12:17am UTC](https://forum.inductiveautomation.com/t/powershell-script/73793/4 "2023-05-17T00:17:10Z")

</div>

Normally Powershell scripts have some tighter default execution policies that you might need to inspect/adjust. See here for some starter information: [about Execution Policies - PowerShell | Microsoft Learn](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_execution_policies?view=powershell-7.3)

---

<div class="post-metadata">

**Author:** ![Muhammad\_Saim](https://avatars.discourse-cdn.com/v4/letter/m/7ab992/32.png) [@Muhammad\_Saim](https://forum.inductiveautomation.com/u/Muhammad_Saim)\
**Post date:** [May 23, 2023, 2:53pm UTC](https://forum.inductiveautomation.com/t/powershell-script/73793/5 "2023-05-23T14:53:28Z")

</div>

@pascal.fragnoud, @kcollins I found an error. It was outside the logger I created.

**Error executing project update script.**

com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last): File "\<[Data\_Management] Update Script\>", line 9, in File "\<[Data\_Management] Update Script\>", line 9, in at java.base/java.lang.ProcessBuilder.start(Unknown Source) at java.base/java.lang.ProcessBuilder.start(Unknown Source) at java.base/java.lang.Runtime.exec(Unknown Source) at java.base/java.lang.Runtime.exec(Unknown Source) at com.inductiveautomation.ignition.common.script.builtin.SystemUtilities.execute(SystemUtilities.java:146) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.base/java.lang.reflect.Method.invoke(Unknown Source) java.io.IOException: java.io.IOException: _ **Cannot run program "C:\Program Files\Inductive Automation\Ignition\data\git-auto-commit.ps1": CreateProcess error=193, %1 is not a valid Win32 application** _

---

<div class="post-metadata">

**Author:** ![kcollins](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kcollins/32/19646_2.png) [@kcollins](https://forum.inductiveautomation.com/u/kcollins)\
**Post date:** [May 23, 2023, 3:02pm UTC](https://forum.inductiveautomation.com/t/powershell-script/73793/6 "2023-05-23T15:02:43Z")

</div>

You might have to use `powershell.exe` to invoke the target `.ps1` script. ref: [https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about\_powershell\_exe?view=powershell-5.1](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_powershell_exe?view=powershell-5.1)

---

<div class="post-metadata">

**Author:** ![Muhammad\_Saim](https://avatars.discourse-cdn.com/v4/letter/m/7ab992/32.png) [@Muhammad\_Saim](https://forum.inductiveautomation.com/u/Muhammad_Saim)\
**Post date:** [May 24, 2023, 1:42pm UTC](https://forum.inductiveautomation.com/t/powershell-script/73793/7 "2023-05-24T13:42:14Z")

</div>

I'm executing

```auto
	system.util.execute([
		"powershell.exe",
		"-File 'C:\Program Files\Inductive Automation\Ignition\data\git-auto-commit.ps1'"
	])

```

but it doesn't seem to be doing anything with no errors and I don't see the afile.txt in the data folder.

git-auto-commit.ps1 (simple create file)

```auto
New-Item afile.txt

```

I also tried

```auto
	import subprocess
	proc = subprocess.Popen(["powershell.exe -File 'C:\Program Files\Inductive Automation\Ignition\data\git-auto-commit.ps1'"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
	proc = subprocess.Popen(['powershell.exe', "-File 'C:\Program Files\Inductive Automation\Ignition\data\git-auto-commit.ps1'"], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
	output = proc.stdout.read()
	logger.warn(output)

```

but both those proc didn't work. First proc gave "[Errno 2] No such file or directory" and second proc gave "-File : The term '-File' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1 + -File 'C:\Program Files\Inductive Automation\Ignition\data\git-auto-c ... + ~~~~~ + CategoryInfo : ObjectNotFound: (-File:String) , CommandNotFou ndException + FullyQualifiedErrorId : CommandNotFoundException"

Thank you guys for the help so far

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 24, 2023, 3:42pm UTC](https://forum.inductiveautomation.com/t/powershell-script/73793/8 "2023-05-24T15:42:05Z")

</div>

You're not structuring your commands correctly. Everywhere there's a _space_ in a raw command line:  
`powershell.exe -File 'C:\Program Files\Inductive Automation\Ignition\data\git-auto-commit.ps1'`  
You need a new entry in the list you pass to system.util.execute or subprocess:

```python
system.util.execute([
		"powershell.exe",
		"-File",
		"'C:\Program Files\Inductive Automation\Ignition\data\git-auto-commit.ps1'"
	])

```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 24, 2023, 5:12pm UTC](https://forum.inductiveautomation.com/t/powershell-script/73793/9 "2023-05-24T17:12:45Z")

</div>

You are almost certainly going to need to double up your backslashes, as those are escape characters in python string constants.

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [May 24, 2023, 6:13pm UTC](https://forum.inductiveautomation.com/t/powershell-script/73793/10 "2023-05-24T18:13:07Z")

</div>

Or use `r"something\\"` to ignore escape characters, unless this doesn't work in jython :X

---

<div class="post-metadata">

**Author:** ![Muhammad\_Saim](https://avatars.discourse-cdn.com/v4/letter/m/7ab992/32.png) [@Muhammad\_Saim](https://forum.inductiveautomation.com/u/Muhammad_Saim)\
**Post date:** [May 25, 2023, 1:39pm UTC](https://forum.inductiveautomation.com/t/powershell-script/73793/11 "2023-05-25T13:39:55Z")

</div>

Thank you everyone for the help!!! This worked

```auto
	system.util.execute([
		"powershell.exe",
		"-File",
		"C:\\Program Files\\Inductive Automation\\Ignition\\data\\git-auto-commit.ps1"
	])

```

I didn't need the single quotes in the path

---

<div class="post-metadata">

**Author:** ![arccitect](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@arccitect](https://forum.inductiveautomation.com/u/arccitect)\
**Post date:** [January 22, 2024, 2:22pm UTC](https://forum.inductiveautomation.com/t/powershell-script/73793/12 "2024-01-22T14:22:08Z")

</div>

New to ignition here, and I'm curious if anyone has any ideas on getting Perspective to launch an RDP session through a powershell script? with the system.util.execute() method?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 22, 2024, 2:27pm UTC](https://forum.inductiveautomation.com/t/powershell-script/73793/13 "2024-01-22T14:27:23Z")

</div>

Perspective runs in a browser. You can't run PowerShell scripts from a browser for security reasons.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [January 22, 2024, 2:57pm UTC](https://forum.inductiveautomation.com/t/powershell-script/73793/14 "2024-01-22T14:57:15Z")

</div>

> [@arccitect](#):
>
> Perspective to launch an RDP session

Why? What are you trying to accomplish?

---

<div class="post-metadata">

**Author:** ![arccitect](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@arccitect](https://forum.inductiveautomation.com/u/arccitect)\
**Post date:** [January 25, 2024, 3:54pm UTC](https://forum.inductiveautomation.com/t/powershell-script/73793/15 "2024-01-25T15:54:43Z")

</div>

Thanks Transistor, I may just build it in Vision then!

Irose, in my deployment the perspective host consolidates about 30 SCADAs into one place so operators can easily respond to alarms without having to check each of these local SCADAs individually. Part of my design limits the functionality of the host to read only for safety & compliance. When live operations demand it, the operator must pull up the local SCADA & operate there. This is accomplished via RDP.

The idea is a gateway script that would act as a shortcut, pulling up an RDP more rapidly for convenience and in the event that we have a gateway crash a quick script to automatically launch all 30 RDPs would be very useful as many of our reporting requirements are time sensitive & unfortunately we do not have robust hardware making this host prone to crashes and endless performance related issues.

Looking forward to hearing your ideas, thanks for the help.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [January 25, 2024, 3:56pm UTC](https://forum.inductiveautomation.com/t/powershell-script/73793/16 "2024-01-25T15:56:31Z")

</div>

@arccitect - Tip: to have someone notified of a response either hit the Reply button under their post or use the `@username` syntax in the post.  
Thanks for the feedback.

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [January 25, 2024, 4:02pm UTC](https://forum.inductiveautomation.com/t/powershell-script/73793/17 "2024-01-25T16:02:10Z")

</div>

> [@arccitect](#):
>
> in the event that we have a gateway crash a quick script to automatically launch

Can't really do anything about this, because if the gateway crashes, you...well...can't use it.

You can't run a Powershell script from a browser, but there is nothing stopping the Gateway from executing a file on the gateway. So, I would use a Gateway Message Handler to run `system.util.execute()`

Of course, that won't help someone who isn't looking at the gateway computer, so there really isn't a way to launch a new session from the gateway on client hardware.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [January 25, 2024, 4:27pm UTC](https://forum.inductiveautomation.com/t/powershell-script/73793/18 "2024-01-25T16:27:38Z")

</div>

Consider using a Microsoft URI scheme for Remote Desktop. Probably works out of the box in MS Edge:

> **[Remote Desktop URI scheme](https://learn.microsoft.com/en-us/windows-server/remote/remote-desktop-services/clients/remote-desktop-uri)**
>
> Learn about the Uniform Resource Identifier scheme for Remote Desktop clients

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [January 25, 2024, 8:41pm UTC](https://forum.inductiveautomation.com/t/powershell-script/73793/19 "2024-01-25T20:41:52Z")

</div>

If you have a Linux server with docker available, you could use guacamole for this. I've got some potential projects needing VNC and Guacamole supports VNC and RDP in a web browser, so you could launch a URL to the guacamole client connection, or embed it in a view or popup.

---

<div class="post-metadata">

**Author:** ![arccitect](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@arccitect](https://forum.inductiveautomation.com/u/arccitect)\
**Post date:** [January 30, 2024, 3:06pm UTC](https://forum.inductiveautomation.com/t/powershell-script/73793/20 "2024-01-30T15:06:11Z")

</div>

@lrose that makes sense.. Face meet palm! Either way it would be very useful to launch a single client session to expedite emergency operations since all manipulations must be performed in the local SCADA. I've already implemented a way to rapidly pull up our password manager for just such, and I'm curious if there may be a way to utilize an authenticated keeper commander session to accomplish this while obfuscating passwords in concert with @pturmel's suggestion for URI:

> **[GitHub - Keeper-Security/Commander: Keeper Commander is a python-based CLI...](https://github.com/Keeper-Security/Commander)**
>
> Keeper Commander is a python-based CLI and SDK interface to the Keeper Security platform. Provides administrative controls, reporting, import/export and vault management. - GitHub - Keeper-Security...

@michael.flagler I desperately wish I was just working solely with Linux... It would make life for me & my team a lot easier in many ways... That would be a brilliant feature, and is truly an excellent suggestion. I'm curious if there is a way to do something similar within the constraints of using Windows?

[Next page](https://forum.inductiveautomation.com/t/powershell-script/73793.md?page=2)
