How to Split an Email Addresses with PowerShell

Table of Contents

Split an Email Addresses with PowerShell

In this blog post, I will show you a PowerShell cmdlet that will split an email address from the @ symbol.

The code below takes a full email address and removes everything that is after the symbol @. After the code is run you will end up with the username only.

$email = "[email protected]"
$userName = $email.Split("@")[0]
$userName
How to Split an Email Addresses with PowerShell

In cases you want to extract the domain only. The below code will remove everything that is before the symbol @.

$email = "[email protected]"
$userName = $email.Split("@")[1]
$userName
How to Split an Email Addresses with PowerShell

Leave a Comment

Required fields are marked *