private/Helpers.psm1

#Stop execution on first unhandled exception
$ErrorActionPreference = "Stop"

function Execute-Command($path, $arguments)
{
    $startInfo = New-Object System.Diagnostics.ProcessStartInfo
    $startInfo.FileName = $path
    $startInfo.RedirectStandardError = $true
    $startInfo.RedirectStandardOutput = $true
    $startInfo.UseShellExecute = $false
    $startInfo.Verb = 'runAs'
    $startInfo.Arguments = $arguments

    $process = New-Object System.Diagnostics.Process
    $process.StartInfo = $startInfo
    $process.Start()
    $process.WaitForExit()

    [PSCustomObject]@{
        stdout = $process.StandardOutput.ReadToEnd()
        stderr = $process.StandardError.ReadToEnd()
        ExitCode = $process.ExitCode  
    }
}