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

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

Not a reader? Watch this related video tutorial:
5/5 - (1 vote)