Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement ManagedConnections in OneShell #17

Open
exactmike opened this issue Dec 13, 2018 · 0 comments
Open

Implement ManagedConnections in OneShell #17

exactmike opened this issue Dec 13, 2018 · 0 comments

Comments

@exactmike
Copy link
Owner

exactmike commented Dec 13, 2018

OneShell is a connection/session manager for Systems/Services that can be accessed via PowerShell. It uses Profiles to implement this functionality, managing the system/service definitions, endpoints, credentials, etc. Connections can be made by OneShell via PowerShell Remoting (eg. Exchange Online, Skype Online, etc.) or via 'Local Connect' (eg. AzureAD via Import-Module and Connect-AzureAD) or a combination of these 2 techniques.

Currently, OneShell's connection/session management is limited to the following features:

  • auto connection to a user defined set of systems
  • on demand connection to user defined system(s)
  • auto grouping of sessions into session management groups for one to many management (eg. Invoke-Command -Session $SessionGroup).
  • on demand testing of connection
  • re-connection to one or more existing connections if needed (if testing shows the connection has failed)

The goal of this issue is to define implementation of these additional features:

  • multiple connections to the same system (for parallel operations, background jobs, etc.)
  • 'clean' disconnection of an existing connection where possible (depending on service type support)
  • tracking of connections to service types to avoid or warn about potential conflicts (for example, connection operations that would clobber existing commands in the local PowerShell session)
  • get all OneShell connections
  • Improved session management groups
  • Improved/Robust support for Prefixing with 'LocalConnect' systems.
    This is needed to manage imports of modules with command prefixing if the user requests it in their profile configuration or connect-oneshellsystem parameters. And to handle disconnection if the same module was previously imported for a different system.

Implementation Proposal Summary

Implementation will require new functions and new connection tracking mechanism(s). The proposed solution would include the following (more detail to follow below):

  • Module variable ManagedConnections array to track each Connection
  • New function Remove-OneShellSystemPSSession (would remove an imported session from being imported but not the session itself)
  • New function Get-OneShellConnection (or Get-OneShellSystemConnection)
  • Update function Import-OneShellSystemPSSession to update ManagedConnections entry(ies)
  • New function Disconnect-OneShellSystem to manage the 'cleanes' disconnection possible for a given ServiceType and connection type (PS Remoting or LocalConnect).

Implementation Proposal Detail

$Script:ManagedConnections

  • Array of PSCustomObject
  • Attributes
    • ManagedConnectionID (Incremented Int)
    • Identity (of the System from the OrgProfile)
    • Name (of the system from the OrgProfile)
    • OrgProfileIdentity
    • OrgProfileName
    • UserProfileIdentity
    • UserProfileName
    • PSSessionName (null for LocalConnect)
    • PSSessionID (null for LocalConnect)
    • Imported (bool for whether the PSSession is imported locally or import-module was used)
    • ImportedModuleName (the auto/random module name PS assigns to imported session modules)
    • ConnectionType (LocalConnect|PSRemoting)
    • PrefixApplied (at import - might be null)
    • EndpointIdentity (might be null)
    • First/Default Connection?

Update function Import-OneShellSystemPSSession

It needs to update a ManagedConnections entry attributes ImportedModuleName, Imported, Prefix

New function Remove-OneShellSystemPSSession

It needs to remove an imported session/session module but leave the session running for later import or disconnection. In other words, it's not doing the job of Remove-PSSession. Instead, it is reversing Import-PSSession (or in OneShell's case Import-OneShellSystemPSSession).

New function Get-OneShellConnection

Parameter Sets

  • all
  • byIdentity
  • byServiceType
  • other?

New function Disconnect-OneShellSystem

Parameter Sets

  • All
  • Identity (all connections for specified system(s) or scoped to ConnectionID)
  • ServiceType (all connections for a servicetype or scoped to ConnectionID)
  • ConnectionID (specific connection(s))

Description

branches depending on ConnectionType (LocalConnect or PSremoting)

  • PSRemoting steps
    • If imported, remove imported module
    • If disconnect command is defined in servicetype, run disconnect command in PSSession
    • Remove PSSession from local session and session management group(s)
  • LocalConnect steps
    • If disconnect command is defined in servicetype, run disconnect command locally
    • if not, optionally warn user (if warning is defined in servicetype). This is because certain connections can persist even through module removal (see MSOnline module for an example).

Autocompleters for parameters for all the above functions

  • for Identity to limit ConnectionIDs
  • for ConnectionID to limit Identities
  • for ServiceType to limit ConnectionIDs and Identities
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants