Q:

PowerShell: Unable to check if display name exists within email address and reverse display name's firstname + lastname

I need to check if a display name exists is within an email address and reverse its lastname + firstname in-case it's backwards. 
Let's assume the email address is test.user@email.com and the display name is user test. 
I need to check if the display name exists within the email address and if firstname and lastname are reversed compared to the email address reverse it so it complies with the email address' firstname + lastname schema. 
I don't even know where to start.  Should I split the email address on .  and @? 

A:

here's how you might do it for a single name.   You will need to re-work it into some kind of loop or make a function out of it, if you have lots of names/addresses to check. 
$userName = "User Test"
$nameParts = $userName. Split(' ')

$userEmail = "test.user@email.com"

if($userEmail -eq "$($nameparts[1]).$($nameParts[0])@email.com")
{
    "'$userEmail' is a valid email for '$userName'"
}
else
{
    "'$userEmail' is NOT a valid email for '$userName'"
}

