Public/InstallHelpers/Install.RunExecutable.Functions.psm1

Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop";
#Requires -Version 5.0


# function BuildRunAsCredential(
# [Parameter(Position=0,mandatory=$true)]
# [string] $runAsUser,

# [Parameter(Position=1,mandatory=$true)]
# [string] $runAsUserPass
# ) {
# $securePassword = ConvertTo-SecureString $runAsUserPass -AsPlainText -Force
# $credential = New-Object System.Management.Automation.PSCredential $runAsUser, $securePassword
# return $credential
# }
# # TODO: Refactor this to elsewhere
# function HandleExitCode(
# [Parameter(mandatory=$true)]
# [int] $code,

# [Parameter(mandatory=$true)]
# [string] $msg
# ) {
# if ($code -ne 0) {
# throw $msg
# # NOTE: Exit with 1 to fail the build
# exit 1;
# }
# }


# TODO
function BuildExeArgs() {
    # TODO
}


function RunExe(
    [Parameter(mandatory=$true)]
    [string] $pathToExe,

    # EX: -v true -h localhost -d TrainingNotifier_Test -i true
    # EX: -v true -h <HOST> -d TrainingNotifier_Test -u <SQL_LOGIN> -p <SQL_LOGIN_PASS>
    [Parameter(mandatory=$true)]
    [string] $argsString
) {
    Write-Host -ForegroundColor Yellow "Running $pathToExe with args $argsString..."
    $process = Start-Process -FilePath $pathToExe -ArgumentList $argsString -PassThru
    $process.WaitForExit()
    return $process.ExitCode
}


Export-ModuleMember -Function "*"