From 41a61adb83c89a5a287ee063e1562695aa5c00f5 Mon Sep 17 00:00:00 2001 From: Nicholas Jackson Date: Thu, 13 Oct 2022 23:25:45 -0700 Subject: [PATCH] docs: add a more pwsh-friendly use case # 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. --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 74f58de09..9ddbd3aa1 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,30 @@ pwsh -NoLogo -NoProfile -Command "$PSES_BUNDLE_PATH/PowerShellEditorServices/Sta > - `$PSES_BUNDLE_PATH` is the root of the PowerShellEditorServices.zip downloaded from the GitHub releases. > - `$SESSION_TEMP_PATH` is the folder path that you'll use for this specific editor session. +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()` + +```powershell +$command = @( + "$PSES_BUNDLE_PATH/PowerShellEditorServices/Start-EditorServices.ps1", + "-BundledModulesPath $PSES_BUNDLE_PATH", + "-LogPath $SESSION_TEMP_PATH/logs.log", + "-SessionDetailsPath $SESSION_TEMP_PATH/session.json", + "-FeatureFlags @()", + "-AdditionalModules @()", + "-HostName 'My Client'", + "-HostProfileId 'myclient'", + "-HostVersion 1.0.0", + "-LogLevel Normal" +)-join " " + +$pwsh_arguments = "-NoLogo -NoProfile -Command $command" +$process = Start-Process pwsh -ArgumentList $arguments -PassThru + +... + +$process.Close(); #$process.Kill(); +``` + Once the command is run, PowerShell Editor Services will wait until the client connects to the Named Pipe. The `session.json` will contain the paths of the Named Pipes that you will connect to.