mercredi 27 novembre 2019

Powershell specific character not match for function

Am trying to create a filter to only run the IF clause in case of the character in the 4 position be either "W", "X", "Y", "Z".

The code so far looks like this:

$name= "123Y567"

if ($name.notcontains("Y"))
{
 "Action 1"
}
  else
{               
  "Action 2"
 }
}

I have tried this as well

$name= "123Y567"

if ($name -notmatch (/^.{4}["Y"]/))
{
 "Action 1"
}
  else
{               
  "Action 2"
 }
}

What could be the best solution for this? but new working with scripting and Powershell in general.

Aucun commentaire:

Enregistrer un commentaire