简体   繁体   中英

How to open .ps1 file in PowerShell ISE in c#

I have a file explorer project, it could display all of the files in treeview, some files are .ps1 files, when user click it, I want to use PowerShell ISE to open it. When I use

Process.Start(filePath)

it always opened with Notepad. Anyone can help?

Here you have an example of poweshell execution without opening window. just replace the -File path and assign or remove parameters when needed:

Process.Start("powershell"," -NoLogo -NonInteractive -File C:\Scripts\YouScript.ps1 -Param1 TestBackup");

Simplest example:

Process.Start("powershell.exe","C:\Scripts\MyScript.ps1");

Another one using string formt and single quotes for arguments:

Process.Start("Powershell.exe", @"""ScriptwithArguments.ps1"" 'arg1' 'arg2 asdf'");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM