-2

I'm trying to create a powershell script that has an if statement depending on what a variable starts with basically.

I have this code:

if($content -contains "fail*") {
    #Not all ID's exist/could not be created. pop up error code :(
    "match"
} else {
    #At this point, we should have a list of hardware id's identifier from our database.
    "no match"
}

The powershell $_POST's data to my server, for a response. If that response starts with fail it should go down the first branch, if it returns anything else, it should go down the other branch.

My PHP code can only return 1 result right now, as I was testing this. This is my php code:

<?
    include("db-connector.php");
    echo "fail - ".$_POST['device'];
?>

The included file contains no output. As you can see, the result should ALWAYS go down the fail branch, but it actually doesn't. Why am I getting this result?

GrumpyCrouton
  • 8,486
  • 7
  • 32
  • 71
  • Read `Get-Help about_Comparison_Operators` carefully. If you need a wildcard use either `-like` or RegEx based `-match` –  Jun 23 '17 at 19:17
  • Sorry everyone, definitely a duplicate, I just didn't know what words to search for to get the result. – GrumpyCrouton Jun 23 '17 at 19:39

1 Answers1

1

Consider using -like if you're using a wildcard to compare to.

about_Comparison_Operators

Maximilian Burszley
  • 18,243
  • 4
  • 34
  • 63