Private/Test-OriAzExrIsInExceptionList.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
39
40
41
42
43
44
45
46
47
48
49
<#
.DESCRIPTION
It get values of item in laguage based on LanguageMask variable
 
.SYNOPSIS
It setup on non-live environemts sending SMS to fake
 
.PARAMETER ListedExceptions
  List of execptions where is the reason to retry
   
.PARAMETER ExceptionMessage
  Execetion message to evaluate
 
.EXAMPLE
  Test-OriAzExrIsInExceptionList `
  -ListedExceptions @("Timeout", "Try again later") `
  -ExceptionMessage 'Something TimeOut Something'
#>

function Test-OriAzExrIsInExceptionList
{
  [OutputType('Boolean')]
  [CmdletBinding()]
  param(

    [Parameter(Mandatory = $true, HelpMessage = "List of exptions")]
    [string[]] $ListedExceptions,

    [Parameter(Mandatory = $true, HelpMessage = "Exception message")]
    [string] $ExceptionMessage

  )
    #in case of any error we want to stop execution, in stderr having the error. Use try-catch to handle errors if needed.
    $ErrorActionPreference = "Stop";

        Write-Debug "-- Test-OriAzExrIsInExceptionList --"
        foreach($OneItem in $ListedExceptions) {
            Write-Debug "OneItem: $OneItem "
        }
    Write-Debug "ExceptionMessage: $ExceptionMessage "

    foreach($OneItem in $ListedExceptions) {
            if($ExceptionMessage -ilike "*$OneItem*") {
                return $true
            }
        }

        return $false
}