You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于优化带时间戳测试邮箱地址生成脚本以支持双击执行的技术问询

Optimized PowerShell Script for Timestamped Test Emails (Double-Click Ready)

This script generates a timestamped test email address (like support-08-30-22-09-19-00@servertest.com), copies it to your clipboard, and gives clear feedback so you know it worked—perfect for quickly grabbing a test email to track logs during troubleshooting.

The Optimized Script

Here's the enhanced version of your script, with usability improvements for double-click execution:

# Configure your email template (easy to modify!)
$emailPrefix = "support-"
$emailDomain = "@servertest.com" # Update this to your preferred test domain

# Generate timestamp in MM-dd-yy-HH-mm-ss format
$timestamp = Get-Date -Format "MM-dd-yy-HH-mm-ss"

# Build the full test email address
$testEmail = "$emailPrefix$timestamp$emailDomain"

# Copy the email to your system clipboard
$testEmail | clip

# Display confirmation message with color coding
Write-Host "✅ Test email copied to clipboard successfully!" -ForegroundColor Green
Write-Host "📧 Copied address: " -ForegroundColor Gray -NoNewline
Write-Host $testEmail -ForegroundColor Cyan

# Pause the window so you can see the confirmation before it closes
Write-Host "`nPress any key to close this window..." -ForegroundColor DarkGray
$null = $Host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")

Key Improvements Over the Original

  • Easy customization: The $emailPrefix and $emailDomain variables let you tweak the email format without rewriting the entire string.
  • Clear feedback: Color-coded messages confirm success and show you exactly what was copied—no guessing if it worked.
  • Persistent window: The final pause keeps the PowerShell window open until you press a key, so you don't miss the confirmation when double-clicking.
  • Cleaner syntax: Used string interpolation ("$var1$var2") instead of concatenation for readability.

How to Use It

  1. Save the script: Copy the code above into a text editor (like Notepad) and save it with a .ps1 extension (e.g., GenerateTestEmail.ps1).
  2. Enable script execution (if needed): By default, PowerShell blocks unsigned scripts. To allow this script to run for your user account, open PowerShell as Administrator and run:
    Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
    
    (This lets you run scripts you write yourself, while blocking unsigned scripts from the internet.)
  3. Double-click to run: Simply double-click the .ps1 file. You'll see a window pop up confirming the email is copied to your clipboard—just paste it wherever you need it!

Bonus: Create a Desktop Shortcut

For even quicker access:

  • Right-click on your desktop → New → Shortcut.
  • In the "Location" field, enter:
    powershell.exe -File "C:\Full\Path\To\Your\GenerateTestEmail.ps1"
    
  • Name the shortcut something like "Generate Test Email" and click Finish. Now you can just double-click the shortcut anytime you need a test email!

内容的提问来源于stack exchange,提问作者Mr.Syrax

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.27 18:57:46