psConsole 1.0.8

A launch utility for starting new console sessions from an existing console session.

ssh, Remote PowerShell, and Web Interfaces are supported.

psConsole

See psConsole in action.


This PowerShell script supports starting ssh or Remote PowerShell sessions from Windows Terminal or a native terminal session. Also supported is launching specific Web Interfaces, Markdown documents, and mp4 or mp3 files from the console.

Best experience is with Windows Terminal since individual tabs can be created per console session, but will work with native terminal consoles too.

Device/Host entries are maintained in the file, sshConfig.xml located in your .ssh directory. If desired, one can maintain the configuration data in a LiteDB database. See details below on how to implement LiteDB support.

Supports listing, adding, changing or removing individual entries along with importing or exporting the configuration file in CSV format in a LiteDB collection.

When a new session is launched and a cooresponding entry is not found in the configuration file, then a series of prompts will be presented to obtain the required details for starting the session.

Optionally, one can edit the configuration file directly using your favorite editor.

psConsole will work within the native terminal console but the remote session will be opened within the current console session rather than opening a new tab.


Usage Examples

Open remote session in a new tab

In Windows Terminal enter Ctrl+Shift+(X) where X matches the profile number that executes psConsole.ps1.

A new tab is opened with a prompt to enter a host name.

Enter SSH/RPS Host name:

If the host name entered has a matching entry in the configuration file, sshConfig.xml, then a remote session is opened in the tab.

If the host name entered does not have a matching entry in sshConfig.xml, then a series of prompts will be presented to gather the required information for starting the remote session.

psConsole Version 1.0.8
    Enter SSH/RPS host name: unknown-Host
    Enter numeric value or a user name [1] user1 or (2) adm_user2 :
    Enter numeric value or domain name
        [1] myCompany.org or (2) myCompany1.org (3) myCompany2.org
    Domain:
    Enter numeric value or PKI private key file name value
        (1) none or [2] caday
    File Name :

Open remote session in the current console

Execute:
    psConsole

A prompt for the desired host name will be presented.

Enter SSH/RPS Host name:

A remote session is either opened or a series of prompts are presented to obtain to the needed information to open the remote session.

Open remote session without a prompt

Execute:
    psConsole Stargate

A remote ssh session is started without a prompt for the host name.

Open remote session from menu selection

Execute:
    psConsole -name *

When using PowerShell 7 and if the module, Microsoft.PowerShell.ConsoleGuiTools is installed a menu will be presented for selection.

psOutGrid

Use the arrow keys to highlight a selection and the space bar to make a selection.


List entries in the file, sshConfig.xml

List all entries in sshConfig.xml

Execute:
    psConsole -name *

List specific entries in sshConfig.xml

Execute:
    pxConsole -name * -device Linux
    psConsole -name cat* -device Linux

List all host entries with a device attribute matching "Linux"
List all host entries with a name start with 'cat' and a device attribute of "Linux"

Creating Markdown entries in sshConfig.xml

Create an entry in the file, sshconfig.xml as follows:

<Host name="MainHome" DataCenter="Home" Usage="Documentation" Device="MD" Org="Home"> <HostName>MainHome.md</HostName> <User>none</User> <IdentityFile>C:\Git-KeyBase\documents\,/git-keybase/documents/</IdentityFile> <Web>0</Web> </Host>

The IdentifyFile node consists of 2 values separated by a comma. The Windows OS directory path and the Linux directory path relative to $HOME.


sshConfig.xml Management

# Execute: tmoConsole -CADIES psConsole Version 1.0.8 Supported operations are: (1) Change (2) Add (3) Delete (4) Import CSV (5) Export CSV (6) Export LiteDB (7) Sync Enter the operational numeric value:

Enter the numeric value for the desired operation.

-CADIES stands for (C)hange (A)add (D)elete (I)mport (E)xport (S)ync

(5) Export CSV exports sshConfig.xml to a CSV file, then add new entries to the CSV file as desired.

(4) Import CSV file will add new entries to sshConfig.xml.

(6) Export LiteDB will export the entries in the sshConfig.xml to a LiteDB collection. This feature was implemented in version 1.0.4 and is experimental has this time. The section LiteDB sshConfig Management outlines the requirements for using LiteDB.

(7) Sync is not implemented at this time.


The psConsole will work within the native terminal console but the remote session will be opened within the current console session rather than opened in a new tab.

Download psConsole

Download sshConfig.xml template

Install Windows Terminal

Best experienced with Windows Terminal because of tab support. It will work with the standard PowerShell console but the remote session will be executed in the existing console session.

Start a PowerShell console session as ADMINISTRATOR.

Install:
    choco install microsoft-windows-terminal

Update:
    choco upgrade microsoft-windows-terminal

Windows Terminal can also be installed with Microsoft App Store, if that feature hasn't been disabled.


Update Windows Terminal settings

Enter the following commands and responses to create WT profiles for executing psConsole from a Windows PowerShell session.

psConsole -NewProfile
Enter the path to WT settings file:
 i.e. C:\Users\<account>\AppData\Local\Packages\Microsoft.WT\LocalState
Enter the menu Title name [Remote]:
Enter the host name [Remote]:
Launch using PowerShell Core Yes or [NO]:

The above creates a WT Profile named, Remote. This will launch a Windows PowerShell session.


The other method for creating a WT profile is to edit the file, settings.json.

Update or create Windows Terminal profile by clicking on the down arrow on the command bar and click on 'Settings'.

Example profile:
{
    "guid": "{d99555dc-969e-40db-9656-6a759f7a5555}",
    "name": "remote",
    "suppressApplicationTitle": true,
    "commandline": "powershell.exe -NoExit -Command psConsole.ps1",
    "startingDirectory": "C:/bin/ps",
    "hidden": false
},

SSH REQUIREMENTS

Verify if Windows OpenSSH feature is installed
    Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'

Install the OpenSSH Client
    Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0

Install the OpenSSH Server (Optional)
    Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

Verify C:\Users\<username>\.ssh folder access
    Folder must be locked down so only <username> has access.

Usage of the sshConfig.xml file is optional but to avoid prompting for credential information there must be a host entry in the file, sshConfig.xml

Download sshConfig.xml template

Copy sshConfig.xml file downloaded the folder to C:\Users\username\.ssh\sshConfig.xml and make the following updates.

VERIFY That the permissions on your .ssh folder are set to exclusive access by your account only.

1. Update account name used by ssh login
    Replace all instances of 'user1' with your user name.
2. If using PKI (Optional)
    Default private PKI file needs to match your account name in the .ssh folder
    Make a copy of private PKI file and/or rename to match your account name.

    Default private PKI file is only used in instances when creating ssh session
    and there isn't a host entry in the sshConfig.xml file.

    Replace all instances of 'user2' with private PKI file.

Modify psConsole.ps1 script as follows.

  1. replace 'myCompany.org' with your default domain name.
  2. replace 'myCompany1.org' with alternative domain name.
  3. replace 'myCompany2.org' with alternative domain name.

Remote Powershell Setup

Verify WinRM is running
    Get-Service WinRM

As Administrator
    Enable-PSremoting -force

Trust all hosts
    Set-Item WSMan:localhost\client\trustedhosts -value *

Verify trusted hosts configuration
    Get-Item WSMan:\localhost\Client\TrustedHosts

Install Credential Manager module

Install-Module -Name **CredentialManager** -scope currentuser

Credentials used for PowerShell remote sessions are stored in Credential Manager.

Do a Search for Credential Manager to launch the GUI management interface.

To register PSGallery repository

Enter the following PowerShell commands.

$Path = 'https://www.powershellgallery.com/api/v2/'

$repo = @{
 Name = 'PSGallery'
 SourceLocation = $Path
 PublishLocation = $Path
 InstallationPolicy = 'Trusted'
}

Register-PSRepository @repo

LiteDB sshConfig Management

The implementation of the noSQL database LiteDB to support the sshConfig data is an experimental feature to determine the value using a noSQL database over using a XML file. At this point, I'm only seeing disadvantages in using a noSQL database rather maintaining the data in a XML file.

If you would like to come to your own conclusion, then the following are the needed requirements.

Install LiteDB Package

Install-Package -Name 'LiteDB' -MinimumVersion '5.0.9' -Source 'nuget.org' -Scope 'CurrentUser' -SkipDependenies

Install PSLiteDB module

Install-Module -Name PSLiteDB -Repository PSGallery -Scope CurrentUser

Generate LiteDB Collection

(6) Export LiteDB will export the entries in the sshConfig.xml to a LiteDB collection. The file, sshConfig.db will be found in your .ssh folder.

By default if the file, sshConfig.xml is found then the XML configuartion will be used, so rename this file and the configuration in the LiteDB will be used.


Version History

Version Date Author Description
1.0.8 03/02/2022 cadayton Bug fixes to better support non-Windows; Added 'Platform' parameter and attribute to limit displayed items to specfic platform.
1.0.7 01/11/2022 cadayton Tweaked to work with Linux console terminal
1.0.6 11/15/2021 cadayton Support for display Markdown file in browser or console
1.0.5 11/10/2020 cadayton Support for launching PowerShell script or cmdlet. Support for Out-ConsoleGridView.
1.0.4 11/07/2020 cadayton LiteDB experimental testing.
1.0.3 10/20/2020 cadayton Create Windows Terminal Profile entry(s).
1.0.2 10/18/2020 cadayton Added host parameter in addition to prompting for a host.
1.0.1 10/12/2020 cadayton Added CRUD, Import, Export, and Sync operations.
1.0.0 09/03/2020 cadayton Initial release