When It Keeps Failing
Jul 7, 2024
Don’t give up! Just Invoke-UntilSuccess! ๐น <# .SYNOPSIS This function executes a command until it succeeds. .DESCRIPTION The Invoke-UntilSuccess function takes a command as an argument and executes it. If the command fails, it retries the command until it succeeds. The function outputs the result of the command and whether the command was executed successfully or not. .PARAMETER commandStr The command to be executed. .EXAMPLE Invoke-UntilSuccess git clone https://github.com/ka-de/polars #> function Invoke-UntilSuccess { try { do { $commandStr = $args -join ' ' Write-Host "Executing command: $commandStr" $output = Invoke-Expression $commandStr Write-Host $output $exitCode = $LASTEXITCODE if ($exitCode -eq 0) { Write-Host "Command executed successfully. ...