Classes/ExeExecuteManager.ps1

class ExeExecuteManager {
    [LibraryContext]$Context
    
    ExeExecuteManager([LibraryContext]$context) {
        $this.Context = $context
    }

    [void]Run([string]$uri, [string]$exepath, [string]$exeargs, [object]$executeList) {
        if ($executeList) {
            foreach ($exec in $executeList) {
                $this.Run($exec.uri, $exec.path, $exec.args, $null)
            }
        }
        elseif ($uri -or $exepath) {
            if ($uri) {
                $this.Context.LogManager.Log("Downloading software from $uri to $exepath")
                Invoke-WebRequest -Uri $uri -OutFile $exepath
            } else {
                #$this.Context.LogManager.Log("URI is null, skipping download step.")
            }
            
            try {
                if (Test-Path $exepath) {
                    $this.Context.LogManager.Log("Executing: $exepath $exeargs")
                    #Invoke-Expression $customCommand
            
                    if ($exeargs) {
                        Start-Process -FilePath $exepath -Args $exeargs -Verb RunAs -Wait
                    } else {
                        Start-Process -FilePath $exepath -Verb RunAs -Wait
                    }
                    $this.Context.LogManager.Log("Executed")
                } else {
                    $this.Context.LogManager.Log("Skipping Executing because file does not exist $exepath")
                }
            }
            catch {
                $this.Context.LogManager.Log("Could not execute command: $_", "ERROR")
            }
        }
    }   
}