Skip to main content
100%

Gist 18921c958a623829bd02bec83deae10b

✓ Published0🌍 Public
PPeleke
Last edited Feb 13, 2020
Created on Feb 13, 2020

This example demonstrates a reusable PowerShell retry utility that wraps a command invocation with configurable retry logic. The function `Retry-Command` accepts a command name, a hashtable of arguments, a retry count, and a delay in seconds, executing the command via the call operator `&` with splatting. It forces `ErrorAction` to `Stop` to ensure errors are caught by a `try/catch` block, then retries the command until success or the maximum attempt limit, using `Start-Sleep` to pause between failures. The code highlights PowerShell’s error handling and parameter validation features.

AI-generated description

Similar vizzes