Apparently there is no native Powershell command to retry a CmdLet. I found a
few examples online but thought I'd try my own.
function Retry-Command {
Param([String] $CommandName,
[hashtable] $CommandArgs = @{},
[int] $MaxRetries=3,
[int] $SleepSeconds=2 )
$retrycount = 0
$CommandArgs.ErrorAction='Stop'
while ($retrycount++ -lt $MaxRetries) {
try {
&$CommandName @CommandArgs
return
}
catch