Managing PowerShell Server from the Command Line

Managing PowerShell Server from the command line may be useful in various scenarios. Any operation that can be performed from the PowerShell Server UI can also be performed by passing a command line parameter to PowerShellServer.exe.

Any setting that can be specified in the UI can also be set directly in the registry.

Contents

  1. Installation
  2. Configuration
  3. Management

Installation

The PowerShell Server setup can be run in silent mode without requiring user interaction.

The available command line parameters are described below:

Parameter Description
/S Indicates that the installer should run in silent mode.
/SNO The serial number to be used during installation. ex:
setup.exe /S /SNO=XISUB-RA1SU-XXXXX-XXXXX-XXXXX
/PATH The installation path if a custom path is desired. ex:
setup.exe /S /SNO=XISUB-RA1SU-XXXXX-XXXXX-XXXXX /PATH=C:\Your\Path

The silent install itself is non-blocking and the command will return immediately. The installation will continue in the background.

If required, the following command can be used to block until installation is complete:

Start-Process setup.exe -ArgumentList @("/S","/SNO=XISUB-RA1SU-XXXXX-XXXXX-XXXXX") -Wait
Note: The /S install option is case sensitive. It must be specified with an uppercase letter.

Configuration

PowerShell Server stores all of its settings in the registry at:

HKEY_LOCAL_MACHINE\SOFTWARE\nsoftware\PowerShell\Server\16

Because of this, all that is necessary for configuration is to create/modify the registry keys that correspond with the desired settings. This can easily be done in a command line environment. For example, modifying the registry to enable SCP support using PowerShell can be done like so:

$path = "HKLM:\SOFTWARE\nsoftware\PowerShell\Server\16"
New-ItemProperty -Path $path -Name EnableSCP -Value 1 -Force
This will create or modify the EnableSCP DWORD value with a value of "1". Note that the -Force parameter causes the value to be overwritten if it already exists. Otherwise, an error will be thrown indicating that the value already exists.

Of course, this is just one way to modify registry. Any method of doing so would suffice. The key point is that PowerShell Server reads the values from the registry for its configuration and all that is necessary to modify the configuration, is to change the registry values. Please refer to the documentation for a list of applicable registry settings.

Management

Command line parameters can also be utilized to manage PowerShell Server. The following is a list of parameters applicable to PowerShellServer.exe:

Parameter Description
/servicestart Starts the service. For instance:
PowerShellServer.exe /servicestart
/servicestop Stops the service. For instance:
PowerShellServer.exe /servicestop
/start Starts PowerShell Server in-process. For instance:
PowerShellServer.exe /start
/stop Stops PowerShell Server when it is running in-process. For instance:
PowerShellServer.exe /start
/restart Restarts PowerShell Server when it is running in-process. For instance:
PowerShellServer.exe /restart
/exit Closes the PowerShell Server process. For instance:
PowerShellServer.exe /exit

Note: When running PowerShell Server in-process, these command line parameters may only be used if the AdminServiceEnabled registry key is set to 1 (True).

When running PowerShell Server as a Windows service, the administration service is also available for management. This service listens by default on port 8122 (defined by the AdminServicePort registry key). The username and password to log in are automatically generated during setup, and correspond with the AdminServiceUsername and AdminServicePassword registry keys. The AdminLocalOnly registry key controls whether the administration service is accessible remotely, and is set to 1 (True) by default.

Logging in to the administration service allows the following cmdlets to be executed:

  • Get-PSSConnections
  • Disconnect-PSSClient -ConnectionId <id>
  • Start-SSHDaemon
  • Stop-SSHDaemon
  • Restart-SSHDaemon
  • Stop-PowerShellServer
  • Exit
By default, any other commands will result in an error. However, this can be controlled via the AdminCommandRegex setting in the registry by using a regular expression to allow/disallow commands.

We appreciate your feedback.  If you have any questions, comments, or suggestions about this article please contact our support team at kb@nsoftware.com.