0

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?

James
  • 2,570
  • 7
  • 34
  • 57

1 Answers1

0

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'");
Carlos Landeras
  • 11,025
  • 11
  • 56
  • 82
  • Hi @Carlos, thanks for your quick reply! I want the file opened in Powershell ISE editor. For example, there're 2 .ps1 files, when I click the first one, open a tab in the ISE and display the file content, click the second one, open a new tab to display the file content. – James Oct 22 '13 at 10:01
  • Change "Powershell.exe" as "Powershell_ise.exe", then it works! – James Oct 22 '13 at 10:07
  • Yeah. Dont remember the exactly exe name – Carlos Landeras Oct 22 '13 at 10:08