mardi 26 janvier 2016

Powershell If Statement -match or -contains not returning correct condition

I'll make this quick.

We are updating our SIP for email addresses and we are going to use a powershell script to monitor when AD is updated and then update the local machine.

I'm to the part where I split the email address at the "@" symbol and I'm looking to the left of the @ symbol.

Example: FirstName.LastName@someplace.com

I can split it correctly where i just get FirstName.LastName

I can split it, but when I go to check the condition if it contains a ".", I can't get a correct true of false.

Example.

I'm looking for email address that contains a "period" or "." to the left of the "@" symbol.

$sipaddress = "FirstName.LastName@someplace.com" $splitname = $sipaddress.Split("@")[0]

at this point, $splitname varible will contain "FirstName.LastName"

if ($splitname -match '.'){ Write-Host "TRUE" } Else{ Write-Host "False" }

this returns TRUE which is perfect

BUT, if I change the variable to like this for testing $sipaddress = "FirstNameLastName@someplace.com"

The the $splitname variable will contain "FirstNameLastName", it still returns TRUE when that is not correct. IT should return false because there is no "."

What am I doing wrong? I tried to use -contains in the If statement but that does not work either.

Is there a way to try and check for a "-match" for the "." ?

Aucun commentaire:

Enregistrer un commentaire