Match Email Subjects Against Standard Set of Strings - Powershell


This topic contains 3 replies, has 2 voices, and was last updated by Profile photo of Karunanidhi Mishra Karunanidhi Mishra 1 year, 1 month ago.

  • Author
  • #29525
    Profile photo of Karunanidhi Mishra
    Karunanidhi Mishra

    Hello Everyone,

    The scenario is I have a table that contains a list of standard issues as shown below,

    New: — Health Service Heartbeat Failure
    This computer is offline
    Jaguar Service Will be Restarted
    Secondary – is down

    I need to compare a string value through the list that has some more added values in it.
    $variable =[string]"Secondary – VM-ABC123 is down"

    if($list -match $variable)
    echo "Standard Issue"
    echo "New Issue"

    – As you could see the string in the variable has the server name in it but the standard issue will not have the server names . How will I match it ?

    Any suggestions will be a great help..
    thanks in advance

  • #29526
    Profile photo of Rob Simmers
    Rob Simmers

    Check out the -Contains operator:

    #Create an array of standard issue subjects
    $stdIssue = "New: — Health Service Heartbeat Failure",
                "This computer is offline"
                "Jaguar Service Will be Restarted"
                "Secondary – is down"
    #Another array that contains some test subjects
    $tests = "Secondary – VM-ABC123 is down", "This computer is offline"
    foreach ($test in $tests) {
        #You can use the -contains operator to see if the
        #subject is in the $stdIssue array
        if ($stdIssue -contains $test) {
            "{0} is a STANDARD issue" -f $test
        else {
            "{0} is a NEW issue" -f $test
  • #29534
    Profile photo of Karunanidhi Mishra
    Karunanidhi Mishra

    @Rob, Thanks for this quick response. will "-contains" will do the needful because you see the string "Secondary – is down" is a standard issue and for a string "Secondary – VM-ABC123 is down" although it has a VM name added to it this should be shown as standard issue and not as new issue.I guess some regex would solve the problem.

  • #29535
    Profile photo of Karunanidhi Mishra
    Karunanidhi Mishra

    I got one solution i.e. if the computer names will be in each line of the $list array, we can just add a * and then do a -like

You must be logged in to reply to this topic.