Skip to content

Commit 9416a8a

Browse files
authored
Add example of starting PSES in a script to readme (#1932)
# Problems Solved: - Executing pwsh with the original command (top, the old one is left in there) causes shells to hang. Not script or automation friendly. - The arguments list is also long enough to scroll off the screen on most devices. Spacing them out over an array that gets joined into a string is a screen-friendly alternative. - However, keeping the old one is good for users who just want a quick copy and paste one-liner.
1 parent a80e422 commit 9416a8a

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,30 @@ pwsh -NoLogo -NoProfile -Command "$PSES_BUNDLE_PATH/PowerShellEditorServices/Sta
5151
> - `$PSES_BUNDLE_PATH` is the root of the PowerShellEditorServices.zip downloaded from the GitHub releases.
5252
> - `$SESSION_TEMP_PATH` is the folder path that you'll use for this specific editor session.
5353
54+
If you are trying to automate the service in PowerShell, You can also run it under `Start-Process` to prevent hanging your script. It also gives you access to Process/PID automation features like `$process.Close()` or `$process.Kill()`
55+
56+
```powershell
57+
$command = @(
58+
"$PSES_BUNDLE_PATH/PowerShellEditorServices/Start-EditorServices.ps1",
59+
"-BundledModulesPath $PSES_BUNDLE_PATH",
60+
"-LogPath $SESSION_TEMP_PATH/logs.log",
61+
"-SessionDetailsPath $SESSION_TEMP_PATH/session.json",
62+
"-FeatureFlags @()",
63+
"-AdditionalModules @()",
64+
"-HostName 'My Client'",
65+
"-HostProfileId 'myclient'",
66+
"-HostVersion 1.0.0",
67+
"-LogLevel Normal"
68+
)-join " "
69+
70+
$pwsh_arguments = "-NoLogo -NoProfile -Command $command"
71+
$process = Start-Process pwsh -ArgumentList $arguments -PassThru
72+
73+
...
74+
75+
$process.Close(); #$process.Kill();
76+
```
77+
5478
Once the command is run,
5579
PowerShell Editor Services will wait until the client connects to the Named Pipe.
5680
The `session.json` will contain the paths of the Named Pipes that you will connect to.

0 commit comments

Comments
 (0)