PowerShell function to execute a command with retry support.

function Execute-Command($command)
{
    $currentRetry = 0
    $success = $false

    do
    {
        try
        {
            & $command
            $success = $true
        }
        catch [System.Exception]
        {
            if ($currentRetry -gt 5)
            {
                throw $_.Exception.ToString()
            }
            else
            {
                Write-Host "Retry '$currentRetry'"
                Start-Sleep -s 1
            }
            $currentRetry = $currentRetry + 1
        }
    } while (!$success)
}

#
# Example Usage:
#

Write-Host "Setting location to $baseDir"
Set-Location $baseDir

if (Test-Path -path $workingDir)
{
    Write-Host "Deleting existing working directory '$workingDir'..."
    Execute-Command -command { del $workingDir -Recurse -Force }
}

Write-Host "Creating working directory $workingDir"
New-Item -Path $workingDir -ItemType Directory