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
![lFFkcWCWFDO0ljhE6WYNMWccUZY0Im6lX3roHAC4Sqal5CLMmJaIxkXowIbD](https://s3.amazonaws.com/s3.bonben365.com/files/2023/lFFkcWCWFDO0ljhE6WYNMWccUZY0Im6lX3roHAC4Sqal5CLMmJaIxkXowIbD.jpg)
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
![8eSzEdjMUE1pBLhVw6E79T09RBDUfwipQpExvufuijdyejelN8jjBZElKyxP](https://s3.amazonaws.com/s3.bonben365.com/files/2023/8eSzEdjMUE1pBLhVw6E79T09RBDUfwipQpExvufuijdyejelN8jjBZElKyxP.jpg)
Not a reader? Watch this related video tutorial:
5/5 - (1 vote)