Shortcuts

By | Published | No Comments

As mentioned in the Pro-Config blog, Shortcuts are the primary UI and integration launch zone.  If your like me you’ve found that PowerShell can get a bit cryptic at times and I’ve found that non-developer admins are at times intimidated when using PowerShell methods. Powershell alias’s do a fairly good job at making the UI a little more usable, but can’t handle parameters, switches, help tasks, etc. This is where Shortcuts come in, addressing the need for a simple and intuitive developer-facing and integration UI.  [Requirement b2.1] Shortcuts encapsulate functions using standard core functions to complete multi-stage tasks. They should be automated as much as possible, reducing the number of parameters needed and allowing complex functions to be executed with a single command, leading to an intuitive usage model. Shortcuts are loaded via Pro-Config and do not need to be reloaded during a PowerShell session.

Shortcuts within FPS Aloha utilize a baked-in design, meaning that it is a fully integrated with all aspects of the system.  Shortcuts typically are function encapsulations that simplify the use of the architecture by combining the core CmdLets into a stream comprising a service.  They are loaded by Pro-Config via the following source:

$cfgShortcuts = Get-ChildItem -Path ($global:pro_CI.RuntimeDrive+"\FPS\Containers\*\*\SC-*.ps1")  -Force -ErrorAction SilentlyContinue | Select-String -Pattern ':ACTIVE'

foreach ($Shortcut in $cfgShortcuts) {

    $SpShortcut = ([string]$ShortCut).split(":")
    ($SpShortcut[0]+':'+$SpShortcut[1])

}

The system utilizes the inherent filesystem strategy to select SC- files (reserved for ShortCuts) that contain the :ACTIVE pattern (indicating active handles). The call retrieves all lines within the Containers directory that match the criteria, typically resulting in one line per Shortcut. Each referenced shortcut is then loaded, and then is ready for use. This method functions flawlessly unless a development handle mistake occurs, causing two versions to be :ACTIVE simultaneously. Due to the sequential design pattern, the most recent active file will appear last in the list, making it the true active file. To resolve this, each shortcut must first check for any other loaded versions, remove them, and then load the current version. Below is a template illustrating the header format of a shortcut.

<# FPS:Containers:Services:SC-[Shortcut]:ACTIVE #>

if (!(Push-NeededFor [shortcut])) {

    # Remove a prior patch if it already exists
    Remove-Item -Path Function:\[shortcut]

} else {

    # Only load the help line if a prior release is not present, otherwise just keep whats there.
    $genShortcuts = @($genShortcuts
    "[shortcut] .......... [Param: [params], Switches: -[switches]] Description. Use the nomenclature Switches(o) when a param or switch is optional."
    )

}

[Key Insight b2.1] If two :ACTIVE shortcuts exist in different patches, the help line for the first loaded shortcut will remain until the error is resolved. Typically, the help line remains unchanged, and the issue goes unnoticed. However, if there are parameter or switch adjustments, the previous help line might be inaccurate, leading to incorrect shortcut assistance.

To begin using Shortcuts, you’ll first need the file that displays the help line generated for each shortcut (SC-Shortcuts.ps1) within the Services module. There are four available switches for the subsystems FPS ConnectKeePassWordPress, and ServiceNow Action centric software, which will be developed in future blog posts. Deprecated shortcuts are shown at the end of the listing produced.

Shortcuts are the only FPS concept employing deprecated, depreciated, and obsolete functionalities. Deprecated Shortcuts are slated for future removal, while depreciated functionalities are typically replaced or updated in newer patches. Obsolete Shortcuts are entirely removed from the system. Although deprecated Shortcuts remain loaded and accessible, their use is not recommended except for legacy purposes. When a Shortcut becomes deprecated, the associated variable and handle stay in an :ACTIVE state. [Key Insight b2.2] No further updates are made to a deprecated Shortcut, distinguishing it from a depreciated one, which would receive updates through standard patch methods. Upon entering an OBSOLETE state, the function is marked as :OBSOLETE.

Once the Shortcuts.ps1 Shortcut has been loaded, the test will look as follows:

PS C:\> shortcuts

General Shortcuts

shortcuts ……….. [Switches(o): -connect -keepass -actions -gen ] Lists all shortcuts. Default=General (-gen)

Deprecated Shortcuts

No Deprecated shortcuts have been defined

Shortcuts serve as the foundation for creating the essential CmdLet encapsulations within the system. Consequently, the typical design process involves outlining the Shortcut first and then developing the core foundational elements with CmdLets. If future core functionality is anticipated, then it should be stubbed out accordingly within the Shortcut to align with its anticipated usage.ted, then it should be stubbed out accordingly within the Shortcut to align with its anticipated usage.

Referenced Source Files

Source for Pro-Config.ps1 and SC-Shortcuts.ps1.

Leave a Reply