From 59997be01ae4da61faedbb48aa5d57f5a5e391c3 Mon Sep 17 00:00:00 2001 From: Marinus Pfund Date: Mon, 12 Apr 2021 09:50:39 +0200 Subject: [PATCH] Add retry to Install-RootCA.ps1 generateSSTFromWU (#3018) * Update Install-RootCA.ps1 added retry behaviour to certutil.exe -generateSSTFromWU * Update Install-RootCA.ps1 removed multi line * fixed pr comments in Install-RootCA.ps1 fixed PR comments --- .../win/scripts/Installers/Install-RootCA.ps1 | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/images/win/scripts/Installers/Install-RootCA.ps1 b/images/win/scripts/Installers/Install-RootCA.ps1 index a5d678088..5b618b450 100644 --- a/images/win/scripts/Installers/Install-RootCA.ps1 +++ b/images/win/scripts/Installers/Install-RootCA.ps1 @@ -42,11 +42,32 @@ function Get-CertificatesWithoutPropId { } $certsWithoutPropId } + +function Invoke-WithRetry { + <# + .SYNOPSIS + Runs $command block until $BreakCondition or $RetryCount is reached. + #> + + param([ScriptBlock]$Command, [ScriptBlock] $BreakCondition, [int] $RetryCount=5, [int] $Sleep=10) + + $c = 0 + while($c -lt $RetryCount){ + $result = & $Command + if(& $BreakCondition){ + break + } + Start-Sleep $Sleep + $c++ + } + $result +} + function Import-SSTFromWU { # Serialized Certificate Store File $sstFile = "$env:TEMP\roots.sst" # Generate SST from Windows Update - $result = certutil.exe -generateSSTFromWU $sstFile + $result = Invoke-WithRetry { certutil.exe -generateSSTFromWU $sstFile } {$LASTEXITCODE -eq 0} if ($LASTEXITCODE -ne 0) { Write-Host "[Error]: failed to generate $sstFile sst file`n$result" exit $LASTEXITCODE