Public/Start-TMConsole.ps1
function Start-TMConsole { <# .SYNOPSIS Runs a new instance of TMConsole .DESCRIPTION Starts a new instance of the TMConsole TransitionManager automation application .PARAMETER VerboseOutput Indicates to use the --verbose switch for TMConsole .PARAMETER AllowInsecureSSL Indicates to use the --allowInsecureSsl switch for TMConsole .EXAMPLE Start-TMConsole .EXAMPLE Start-TMConsole -AllowInsecureSSL -VerboseOutput .OUTPUTS A boolean value indicating if the given number is a prime number #> [CmdletBinding()] # Always add CmdletBinding to expose the common Cmdlet variables # [OutputType([System.Diagnostics.Process])] # Add this if the function has an output What about with PassThru? param( [Parameter(Mandatory = $false)] [String] $Path, [Parameter(Mandatory = $false)] [Switch] $VerboseOutput, [Parameter(Mandatory = $false)] [Switch] $AllowInsecureSSL, [Parameter(Mandatory = $false)] [Switch] $PassThru ) begin { ## Handle OS Specific - Windows if ($IsWindows) { ## Provide a default path for Windows if (-Not $Path) { $Path = 'C:\Program Files\TransitionManager\tmconsole\tmconsole.exe' } ## Check the Path if (-Not (Test-Path -Path $Path)) { throw "TMConsole was not found at: $($Path)" } } } process { ## Start TMConsole on Windows if ($IsWindows) { ## Setup Standard Process Options $TMConsoleProcInfo = New-Object System.Diagnostics.ProcessStartInfo $TMConsoleProcInfo.FileName = $Path $TMConsoleProcInfo.UseShellExecute = $false $TMConsoleProcInfo.CreateNoWindow = $false $TMConsoleProcInfo.WindowStyle = 'Normal' ## Redirect Standard Streams $TMConsoleProcInfo.RedirectStandardError = $false $TMConsoleProcInfo.RedirectStandardOutput = $false $TMConsoleProcInfo.RedirectStandardInput = $false ## Add the Parameters if ($AllowInsecureSSL) { $TMConsoleProcInfo.Arguments += ' --allow-insecure-ssl' } if ($VerboseOutput) { $TMConsoleProcInfo.Arguments += ' --verbose' } ## Run a "Key Test" SSH Session $TMConsoleProc = New-Object System.Diagnostics.Process $TMConsoleProc.StartInfo = $TMConsoleProcInfo try { ## Run the TMConsole Client [Void]$TMConsoleProc.Start() } catch { throw $_ } ## Return the TMConsole Process if ($PassThru) { $TMConsoleProc } } } end { # Cleanup resources # Will be executed only once per function call. # This block can be omitted } } |