Public/ps1/Configuration/Help/Get-ApprxrHelp.ps1

function Get-ApprxrHelp {
    param(
        [string]$OperationFilter
    )
    $commands = @(
        @{ Name = 'Get-ApprxrAuthenticationId'; Synopsis = 'Generates or returns an authentication ID for Apprxr authentication scenarios.'; Description = 'Returns the provided ID if present, otherwise constructs an ID using the channelId and hostURI, or hostURI and type if channelId is not provided.'; Usage = 'Get-ApprxrAuthenticationId -channelId ''abc'' -hostURI ''https://example.com/'' -type ''user''' },
        @{ Name = 'Set-ApprxrAuthenticationRoute'; Synopsis = 'Sets the authentication route configuration for a given host and channel.'; Description = 'This function creates and stores an authentication path object for a specific host URI, channel, and user credentials.'; Usage = '' },
        @{ Name = 'Get-ApprxrFileWatcherLocations'; Synopsis = 'Lists all configured Apprxr file watcher locations.'; Description = 'Retrieves and displays all file watcher location entries from the configuration, including their properties.'; Usage = '' },
        @{ Name = 'Remove-ApprxrFileWatcherLocation'; Synopsis = 'Removes a file watcher location from the Apprxr configuration.'; Description = 'Calls the private Remove-ApprxrFileWatcherLocationEntry function to remove a file watcher location by name and logs the action.'; Usage = '' },
        @{ Name = 'Set-ApprxrFileWatcherLocation'; Synopsis = 'Sets up a monitored location configuration for the Apprxr file watcher.'; Description = 'Uses Set-ApprxrConfigurationValue to store location settings for the file watcher. Each location setting includes:'; Usage = '' },
        @{ Name = 'Get-ApprxrBaseConfiguration'; Synopsis = 'Retrieves the base configuration for Apprxr, including user, password, and tenant.'; Description = 'Returns a hashtable containing the user name, secure password, and tenant by reading configuration values using Get-ApprxrConfigurationValue.'; Usage = 'Get-ApprxrBaseConfiguration' },
        @{ Name = 'Get-ApprxrConfiguration'; Synopsis = 'Retrieves the Apprxr configuration from the config'; Description = 'Ensures the configuration file exists, then reads and returns its contents as a PowerShell object.'; Usage = 'Get-ApprxrConfiguration' },
        @{ Name = 'Get-ApprxrConfigurationFolder'; Synopsis = 'Returns the folder path used for Apprxr configuration storage.'; Description = 'Returns the LOCALAPPDATA path for ApprxrConnect, creating it if it does not exist.'; Usage = 'Get-ApprxrConfigurationFolder' },
        @{ Name = 'Get-ApprxrConfigurationValue'; Synopsis = 'Retrieves a configuration value from the Apprxr config file.'; Description = 'Reads the specified configuration value from config'; Usage = 'Get-ApprxrConfigurationValue -name ''UserName'' -secure' },
        @{ Name = 'Get-ApprxrUrlHost'; Synopsis = 'Get the tenant url'; Description = 'Returns the url host'; Usage = 'An example' },
        @{ Name = 'Install-ApprxrConfigurationBase'; Synopsis = 'Installs the base configuration for Apprxr, including storing remote connection credentials and log settings.'; Description = 'Stores the provided tenant, credential, and log configuration values securely using Set-ApprxrConfigurationValue and Set-LogConfiguration.'; Usage = '' },
        @{ Name = 'Remove-ApprxrConfigurationValue'; Synopsis = 'Removes a configuration value from the Apprxr config file.'; Description = 'Deletes the specified property from config'; Usage = 'Remove-ApprxrConfigurationValue -name ''UserName''' },
        @{ Name = 'Set-ApprxrConfigurationValue'; Synopsis = 'Sets a configuration value in the Apprxr config file.'; Description = 'Writes or updates the specified property in config'; Usage = 'Set-ApprxrConfigurationValue -name ''UserName'' -value ''admin''' },
        @{ Name = 'Get-ApprxrInstallationHelp'; Synopsis = 'Shows installation help and options for Apprxr setup.'; Description = 'Presents a menu for SQL Gateway or File Watcher setup help, and shows the relevant instructions based on user input.'; Usage = '' },
        @{ Name = 'Install-ApprxrLogging'; Synopsis = 'Initializes the Apprxr log configuration by creating the configuration file with default or provided settings.'; Description = 'Uses Set-LogConfiguration to create and store the log configuration file. If parameters are not provided, defaults are used.'; Usage = '' },
        @{ Name = 'Load-ApprxrLogConfiguration'; Synopsis = 'Loads the Apprxr log configuration from stored configuration values.'; Description = 'Retrieves log hours, log folder, and log retention settings from the configuration and returns them as a hashtable.'; Usage = 'Load-ApprxrLogConfiguration' },
        @{ Name = 'Set-ApprxrLogConfiguration'; Synopsis = 'Sets the log configuration for Apprxr.'; Description = 'Stores log folder path, log retention hours, and log file retention count in the configuration. Uses defaults if values are not provided.'; Usage = '' },
        @{ Name = 'Install-ApprxrService'; Synopsis = 'Installs Apprxr as a Windows service using NSSM (Non-Sucking Service Manager).'; Description = 'Downloads and extracts NSSM to the specified installation folder (or the Apprxr configuration folder if not specified) if not already present. Configures a Windows service to run Apprxr as a background service using PowerShell and NSSM. The service name and entrypoint can be extended with a custom string using the NameExtension parameter. If NameExtension is provided, it is appended to the service name and Start-Apprxr command, and saved to configuration for consistent service management by other Apprxr service commands.'; Usage = 'Install-ApprxrService
    # Installs the service as ''ApprxrService'' running ''Start-Apprxr'' from the Apprxr module, using the default configuration folder.
---
Install-ApprxrService -NameExtension ''Test''
    # Installs the service as ''ApprxrServiceTest'' running ''Start-ApprxrTest'', and saves ''Test'' as the ServiceNameExtension in configuration.
---
Install-ApprxrService -NameExtension ''Prod''
    # Installs the service as ''ApprxrServiceProd'' running ''Start-ApprxrProd''.
---
Install-ApprxrService -InstallationFolder ''D:\Services\Apprxr''
    # Installs the service and NSSM in the specified folder instead of the default configuration folder.
---
Install-ApprxrService -NameExtension ''QA'' -InstallationFolder ''D:\Services\ApprxrQA''
    # Installs the service as ''ApprxrServiceQA'' running ''Start-ApprxrQA'', and installs NSSM in the specified folder.
---
Install-ApprxrService -NssmArch Win32
    # Installs the service using the win32 version of NSSM.
---
Install-ApprxrService -NssmArch Generic
    # Installs the service using the first nssm.exe found in the extracted folder (generic selection).
---
Install-ApprxrService -RunAsUser ''DOMAIN\\ServiceUser''
    # Installs the service to run as the specified user. You will be prompted for the password.
---
Install-ApprxrService -NameExtension ''Prod'' -RunAsUser ''.\\LocalUser''
    # Installs the service as ''ApprxrServiceProd'' running ''Start-ApprxrProd'', and configures it to run as the specified local user.'
 },
        @{ Name = 'Remove-ApprxrService'; Synopsis = 'Removes the Apprxr Windows service.'; Description = 'Stops and deletes the Apprxr Windows service using the correct service name, optionally using an NameExtension.'; Usage = '' },
        @{ Name = 'Restart-ApprxrService'; Synopsis = 'Restarts the Apprxr Windows service.'; Description = 'Stops and then starts the Apprxr service using standard Windows service management cmdlets.'; Usage = '' },
        @{ Name = 'Start-ApprxrService'; Synopsis = 'Starts the Apprxr Windows service.'; Description = 'Starts the Apprxr service using standard Windows service management cmdlets. The service name can be specified using the NameExtension parameter, or determined from configuration for the current session.'; Usage = 'Start-ApprxrService -NameExtension ''Test''
        # Starts the service ''ApprxrService_Test''.'
 },
        @{ Name = 'Stop-ApprxrService'; Synopsis = 'Stops the Apprxr Windows service.'; Description = 'Stops the Apprxr service using standard Windows service management cmdlets. The service name can be specified using the NameExtension parameter, or determined from configuration for the current session.'; Usage = 'Stop-ApprxrService -NameExtension ''Test''
        # Stops the service ''ApprxrService_Test''.'
 },
        @{ Name = 'Get-ApprxrSqlConfiguration'; Synopsis = 'Retrieves the SQL configuration for Apprxr.'; Description = 'Returns a hashtable containing the SQL connection string from the configuration, using a secure value.'; Usage = 'Get-ApprxrSqlConfiguration' },
        @{ Name = 'Install-ApprxrRemoteControllerSQL'; Synopsis = 'Installs the remote controller SQL configuration for Apprxr.'; Description = 'Stores the SQL connection string and related configuration for remote controller operations in Apprxr.'; Usage = 'Install-ApprxrRemoteControllerSQL -Tenant ''tenant1'' -Credential (Get-Credential) -SqlConnectionString ''Server=.;Database=Test;...''' },
        @{ Name = 'Start-Apprxr'; Synopsis = 'Starts the Apprxr service and all configured pipelines.'; Description = 'Runs log management and then starts all Apprxr pipelines by invoking Start-ApprxrPipelines.'; Usage = 'Start-Apprxr' },
        @{ Name = 'Start-ApprxrSession'; Synopsis = 'Starts an Apprxr session and keeps it running.'; Description = 'Starts all Apprxr pipelines and then enters an infinite loop, keeping the session alive by sleeping for one hour at a time.'; Usage = 'Start-ApprxrSession' },
        @{ Name = 'Stop-ApprxrJob'; Synopsis = 'Stops a running Apprxr job by name.'; Description = 'Finds and stops jobs whose names contain ''Apprxr'' using the provided task information. Logs the action and removes the job from the job list.'; Usage = 'Stop-ApprxrJob -taskInformation @{ name = ''Job1'' }' },
        @{ Name = 'Start-ApprxrUpgrade'; Synopsis = 'Upgrades the Apprxr module to the latest version.'; Description = 'Removes, uninstalls, and reinstalls the Apprxr module, then reloads it into the current session.'; Usage = 'Start-ApprxrUpgrade' },
        @{ Name = 'Send-FileToVDB'; Synopsis = 'Sends a file to VDB, optionally encoding as base64.'; Description = 'Reads a file, optionally encodes its content as base64, generates a key from the first 8 characters of the filename plus a hash, and sends it to VDB using Set-ApprxrVDBEntry.'; Usage = '' },
        @{ Name = 'Start-ApprxrFileWatcher'; Synopsis = 'Starts a file watcher for a specific Apprxr location by name.'; Description = 'Checks if a watcher job for the given location is already running and stops it before starting a new watcher job for that location. Uses Watch-ApprxrFolder to monitor the specified folder and filter.'; Usage = 'Start-ApprxrFileWatcher -Name ''Location1''
    Starts a watcher for ''Location1'', stopping any existing watcher job for that name first.'
 },
        @{ Name = 'Start-ApprxrFileWatchers'; Synopsis = 'Starts all file watchers for all configured Apprxr watch folders.'; Description = 'Reads all available file watcher locations from configuration and starts a background task for each using Watch-ApprxrFolder. Used to initialize all watchers at once.'; Usage = 'Start-ApprxrFileWatchers
    Starts all configured file watchers.'
 },
        @{ Name = 'Start-ApprxrJobFile'; Synopsis = 'Handles file jobs for Apprxr by saving, moving, or overwriting files based on input parameters.'; Description = 'Decodes a base64-encoded file and saves it to the specified location. Handles existing files according to the specified mode: error, move, or overwrite.'; Usage = 'Start-ApprxrJobFile -Base64File $b64 -FileLocation ''C:\Temp'' -Mode ''overwrite'' -FileName ''test.txt''' },
        @{ Name = 'Stop-ApprxrFileWatcherLocation'; Synopsis = 'Stops all running watcher jobs for a given Apprxr file watcher location.'; Description = 'Finds and stops all background jobs associated with the specified file watcher location name, and logs the action. Used for cleanup and management of watcher jobs.'; Usage = 'Stop-ApprxrFileWatcherLocation -Name ''Location1''
    Stops all watcher jobs for ''Location1''.'
 },
        @{ Name = 'Stop-ApprxrFileWatchers'; Synopsis = 'Stops all running Apprxr file watcher jobs for all configured locations.'; Description = 'Finds and stops all background jobs associated with Apprxr file watcher locations, and logs each action. Used for cleanup and management of all watcher jobs.'; Usage = 'Stop-ApprxrFileWatchers
    Stops all watcher jobs for all configured locations.'
 },
        @{ Name = 'Start-ApprxrJobHtml'; Synopsis = 'Executes an HTTP job for Apprxr, handling authentication, headers, and response parsing.'; Description = 'Sends an HTTP request (GET or POST) to a specified URL with provided headers, body, and authentication. Handles authentication via Set-ApprxrAuthenticationRoute, logs all request and response details, and returns a structured result. Handles errors and extracts detailed error information from the response.'; Usage = 'Start-ApprxrJobHtml -taskInformation @{ url = ''https://example.com/api''; httpMethod = ''POST''; headers = @{ Authorization = ''Bearer ...'' }; body = $jsonBody; contentType = ''application/json'' }
---
Start-ApprxrJobHtml -taskInformation $taskInfo -DebugMode'
 },
        @{ Name = 'Create-ApprxrPipeline'; Synopsis = 'Creates a new Apprxr pipeline and starts its remote job thread.'; Description = 'Sets configuration values for the pipeline''s sleep interval and direct processing flag, then starts the remote job thread for the pipeline.'; Usage = 'Create-ApprxrPipeline -name ''Pipeline1'' -sleep 5 -directProcessing $true' },
        @{ Name = 'Create-ApprxrPipelineJob'; Synopsis = 'Creates a new Apprxr pipeline job with the specified parameters.'; Description = 'This function initializes a new pipeline job by calling Create-Pipeline with the provided job parameters, including name, wait time, and direct processing flag.'; Usage = 'Create-ApprxrPipelineJob -jobParam $job' },
        @{ Name = 'Get-ApprxrPipelines'; Synopsis = 'Retrieves all Apprxr pipeline names from the configuration.'; Description = 'This function extracts all pipeline names from the Apprxr configuration by searching for properties containing ''Sleep'' and removing the suffix.'; Usage = 'Get-ApprxrPipelines' },
        @{ Name = 'Get-ApprxrRemoteJob'; Synopsis = 'Retrieves and executes a remote job for a specified Apprxr pipeline.'; Description = 'Fetches a job assignment from the remote server for the given pipeline, processes the job, and logs the result. Supports multiple job types:'; Usage = 'Get-ApprxrRemoteJob -pipeline ''Pipeline1''
    # Retrieves and executes a remote job for the ''Pipeline1'' channel.
---
Get-ApprxrRemoteJob -pipeline ''Default''
    # Retrieves and executes a remote job for the default channel.'
 },
        @{ Name = 'Get-ApprxrResult'; Synopsis = 'Retrieves a result from a remote API endpoint using Apprxr authentication.'; Description = 'Sends a GET or POST request to the specified API endpoint, using a bearer token for authentication. Handles token renewal if the request fails due to authentication.'; Usage = 'Get-ApprxrResult -request ''api/data'' -body $jsonBody' },
        @{ Name = 'Remove-ApprxrPipelineJob'; Synopsis = 'Removes an Apprxr pipeline job from the configuration.'; Description = 'This function deletes the configuration value for a pipeline job, effectively removing it from the Apprxr system.'; Usage = 'Remove-ApprxrPipelineJob -jobParam $job' },
        @{ Name = 'Start-ApprxrPipelines'; Synopsis = 'Starts all Apprxr pipeline jobs.'; Description = 'This function retrieves all pipeline names and starts a remote job thread for each, including a default receiver.'; Usage = 'Start-ApprxrPipelines' },
        @{ Name = 'Start-ApprxrRemoteJobThread'; Synopsis = 'Starts a remote job thread for a specified Apprxr pipeline.'; Description = 'Manages background jobs for the given pipeline name, stopping any non-running jobs and starting a new job thread as needed.'; Usage = 'Start-ApprxrRemoteJobThread -name ''Pipeline1''' },
        @{ Name = 'Stop-ApprxrJob'; Synopsis = ''; Description = 'Stop left connect job'; Usage = 'An example' },
        @{ Name = 'Stop-ApprxrJobs'; Synopsis = 'Stops all running Apprxr jobs.'; Description = 'This function finds all running jobs whose names contain ''Apprxr'' and stops and removes them. Used for cleanup and job management.'; Usage = 'Stop-ApprxrJobs' },
        @{ Name = 'Get-ApprxrLog'; Synopsis = 'Retrieves log file contents for the Apprxr module.'; Description = 'Reads the log file specified in $LogManagement'; Usage = 'Get-ApprxrLog
    Returns the current contents of the log file.'
 },
        @{ Name = 'Log-Apprxr'; Synopsis = 'Writes a log message to the configured log file for Apprxr operations.'; Description = 'The Log-Apprxr function appends a timestamped message to the log file specified in the $LogManagement'; Usage = 'Log-Apprxr -msg "Watcher started for folder X"
---
Log "Job completed successfully"'
 },
        @{ Name = 'Log-ApprxrManagement'; Synopsis = 'Manages log file retention and rotation for Apprxr logs.'; Description = 'The Log-ApprxrManagement function checks the log file''s last write time and rotates the log if it is older than the configured retention period. It also enforces the maximum number of log files by deleting the oldest log file if the retention count is exceeded.'; Usage = 'Log-ApprxrManagement' },
        @{ Name = 'Move-ApprxrLogFile'; Synopsis = 'Rotates the current Apprxr log file by renaming it with a timestamp extension.'; Description = 'The Move-ApprxrLogFile function renames the current log file by appending a Unix timestamp to its name. This is used for log rotation, allowing new log files to be created while retaining old logs for reference or retention policies.'; Usage = 'Move-ApprxrLogFile' },
        @{ Name = 'Start-ApprxrJobSql'; Synopsis = 'Executes a SQL job for Apprxr using provided task information.'; Description = 'Connects to the configured SQL database and executes the command specified in the taskInformation parameter. Returns the result or an error message.'; Usage = 'Start-ApprxrJobSql -taskInformation @{ command = ''SELECT * FROM Users'' }' },
        @{ Name = 'Start-ApprxrSqlCommand'; Synopsis = 'Executes a SQL command using Apprxr''s job infrastructure.'; Description = 'This function receives a SQL command string, wraps it in the required taskInformation structure, and calls Start-ApprxrJobSql to execute it.'; Usage = '' },
        @{ Name = 'Set-ApprxrVDBEntry'; Synopsis = 'Sets a VDB entry with key, database name, and TTL.'; Description = 'Creates an object with properties: InnerObject (string), Key, DatabaseName, and TTL (default 0). The result is wrapped in an object and passed to Get-ApprxrResult.'; Usage = '' }
    )
    if ($OperationFilter) {
        $filtered = $commands | Where-Object { $_.Name -like "*" + $OperationFilter + "*" }
    } else {
        $filtered = $commands
    }
    $filtered | ForEach-Object {
        Write-Host "Command: $($_.Name)" -ForegroundColor Cyan
        Write-Host "Synopsis: $($_.Synopsis)" -ForegroundColor Yellow
        Write-Host "Description: $($_.Description)" -ForegroundColor White
        Write-Host "Usage: $($_.Usage)" -ForegroundColor Green
        Write-Host ("{0}" -f ("-" * 40)) -ForegroundColor DarkGray
    }
}