Question

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?

Était-ce utile?

La solution

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'");
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top