functions/invoke/Invoke-ErrorProne.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
function Invoke-ErrorProne { param( [Parameter(Mandatory = $true)] [scriptblock]$Script, [Parameter(Mandatory = $false)] [scriptblock]$OnExit, [Parameter(Mandatory = $false)] [char]$ResolveChar = 'N', [Parameter(Mandatory = $false)] [string]$ResolveMessage = "Please resolve this issue end press any key to continue or [$ResolveChar] to exit" ) process { do { try { Invoke-Command -ScriptBlock $Script -ErrorAction Stop $commandError = $false } catch { $ex = $_.Exception $commandError = $true Write-WarningLog -MessageTemplate $ex.Message -Exception $ex if ((Read-HostColored $ResolveMessage) -eq $ResolveChar) { if ($null -ne $OnExit) { Invoke-Command $OnExit } else { exit } } } } while ($commandError) } } |