New-Email.ps1
19 Sep 2025Description
Purpose
Generates a test email in the format [email protected] and adds the result to the clipboard.
Detailed Description
Generates a test email in the format [email protected] and adds the result to the clipboard.
Formats available via parameters:
-
[email protected] (no parameters)
-
[email protected] (IncludeTime parameter)
-
[email protected] (Suffix parameter)
-
[email protected] (IncludeTime and Suffix parameters)
-
[email protected] (NoDate and Suffix parameters)
-
[email protected] (NoDateparameter)
Usage
Example 1
Generates a new test email in the format abc+yyyyMMdd_test@xyz.com
New-Email -Suffix test
Example 2
Generates a new test email in the format abc+yyyyMMdd_HHmmss_test@xyz.com
New-Email -Suffix test -IncludeTime
Example 3
Generates a new test email in the format abc+yyyyMMdd_HHmmss_test@xyz.com (IncludeTime overrides NoDate)
New-Email -Suffix test -IncludeTime -NoDate
Example 4
Generates a new test email in the format abc+test@xyz.com
New-Email -Suffix test -NoDate
Notes
Author: Rob Green
Script
<#
.SYNOPSIS
Generates a test email in the format [email protected] and adds the result to the clipboard.
.DESCRIPTION
Generates a test email in the format [email protected] and adds the result to the clipboard.
Formats available via parameters:
- [email protected] (no parameters)
- [email protected] (IncludeTime parameter)
- [email protected] (Suffix parameter)
- [email protected] (IncludeTime and Suffix parameters)
- [email protected] (NoDate and Suffix parameters)
- [email protected] (NoDateparameter)
.PARAMETER Phrase
Adds this string as a suffix to the email address, e.g. [email protected].
.PARAMETER Email
Email address to use.
.PARAMETER NoClipboard
If supplied the output will not be written to the clipboard.
.PARAMETER NoDate
If supplied the generated email will not contain the current date in yyyyMMdd format. Ignored if IncludeTime is supplied.
.PARAMETER IncludeTime
If supplied the generated email will add the time after the current date in yyyyMMdd_HHmmss format. Overrides NoDate parameter.
.EXAMPLE
Generates a new test email in the format [email protected]
New-Email -Suffix test
.EXAMPLE
Generates a new test email in the format [email protected]
New-Email -Suffix test -IncludeTime
.EXAMPLE
Generates a new test email in the format [email protected] (IncludeTime overrides NoDate)
New-Email -Suffix test -IncludeTime -NoDate
.EXAMPLE
Generates a new test email in the format [email protected]
New-Email -Suffix test -NoDate
.OUTPUTS
System.String. Awesome email.
.NOTES
Author: Rob Green
.INPUTS
You can pipe objects to these parameters.
- Suffix [string]
#>
function New-Email {
param (
[Parameter(Mandatory = $false, ValueFromPipeline = $true, Position = 0, HelpMessage = "Adds this string as a suffix to the email address, e.g. [email protected].")]
[string]$Suffix,
[Parameter(Mandatory = $false, Position = 1, HelpMessage = "Email address to use.")]
# [ValidateSet (, "[email protected]", "[email protected]")]
[string]$Email = "[email protected]",
[Parameter(Mandatory = $false, HelpMessage = "If supplied the output will not be written to the clipboard.")]
[switch]$NoClipboard,
[Parameter(Mandatory = $false, HelpMessage = "If supplied the generated email will not contain the current date in yyyyMMdd format. Ignored if IncludeTime is supplied.")]
[switch]$NoDate,
[Parameter(Mandatory = $false, HelpMessage = "If supplied the generated email will add the time after the current date in yyyyMMdd_HHmmss format. Overrides NoDate parameter.")]
[switch]$IncludeTime
)
$parts = $Email.Split('@')
# ascertain the date format to use
$dateFormat = $IncludeTime.IsPresent ? "yyyyMMdd_HHmmss" : "yyyyMMdd"
# generate the date string to be included in the output. IncludeTime overrides NoDate
$date = $NoDate.IsPresent -and -not $IncludeTime.IsPresent ? "" : "$([System.DateTime]::Now.ToString($dateFormat))_"
# ascertain whether a suffix should be added to the output
$suffix = [String]::IsNullOrWhiteSpace($Suffix) ? "" : $Suffix
# build the output email
$email = "$($parts[0])+$($date)$($suffix)@$($parts[1])"
if (-Not $NoClipboard.IsPresent) {
$email | Set-Clipboard -PassThru
Write-Host("Copied to clipboard")
}
else {
Write-Host $email
}
}
Download
Please feel free to copy parts of the script or if you would like to download the entire script, simply click the download button. You can download the complete repository in a zip file by clicking the Download link in the menu bar on the left hand side of the page.
Report Issues
You can report an issue or contribute to this site on GitHub. Simply click the button below and add any relevant notes. I will attempt to respond to all issues as soon as possible.