param ( [string]$Url = 'https://www.python.org/ftp/python/3.12.4/python-3.12.4.exe', [string[]]$Arguments = @() ) $tempFilePath = [System.IO.Path]::Combine([System.IO.Path]::GetTempPath(), [System.IO.Path]::GetRandomFileName() + ".exe") try { Invoke-WebRequest -Uri $Url -OutFile $tempFilePath $process = New-Object System.Diagnostics.Process $process.StartInfo.FileName = $tempFilePath $process.StartInfo.Arguments = $Arguments -join " " # Convert array to a space-separated string $process.StartInfo.UseShellExecute = $false $process.StartInfo.RedirectStandardOutput = $true $process.StartInfo.RedirectStandardError = $true $process.StartInfo.CreateNoWindow = $true $process.add_OutputDataReceived({ if ($_.Data) { [Console]::WriteLine($_.Data) } }) $process.add_ErrorDataReceived({ if ($_.Data) { [Console]::WriteLine($_.Data) } }) $process.Start() | Out-Null $process.BeginOutputReadLine() $process.BeginErrorReadLine() $process.WaitForExit() } catch { [Console]::WriteLine("An error occurred: $_") } finally { if (Test-Path $tempFilePath) { Remove-Item $tempFilePath -Force } }