Monday, 29 December 2008

Validate-EmailAddress.ps1

  1. <# 
  2. .SYNOPSIS 
  3.     Validates an email address using a web service 
  4. .DESCRIPTION 
  5.     This script uses the New-WebServiceProxy cmdlet to 
  6.     create a web service proxy. Then it calls that proxy 
  7.     to Validate an email address.  
  8. .NOTES 
  9.     File Name  : validate-emailaddress.ps1 
  10.     Author     : Thomas Lee - tfl@psp.co.uk 
  11.     Requires   : PowerShell V2 CTP3 
  12. .LINK 
  13.    Script posted to: 
  14.    http://www.pshscripts.blogspot.com 
  15. .INPUTTYPE 
  16.    String(s) representing email address to validate 
  17. .RETURNVALUE 
  18.    [Boolean] - whether email address was valid 
  19. .EXAMPLE 
  20.     Run from PowerShell Prompt: 
  21.     PS C:\foo> .\Validate-EmailAddress "tfl@psp.co.uk” 
  22.     True 
  23. .EXAMPLE 
  24.     Run from Pipeline: 
  25.     PS C:\foo> "tfl@psp.co.uk", "foo@foo.bar" | .\Validate-EmailAddress 
  26.     True 
  27.     False 
  28. .PARAMETER addr 
  29.     A string, or array of strings representing email addresses to check 
  30. #> 
  31.  
  32. param( 
  33. [Parameter(Position=0, Mandatory=$FALSE, ValueFromPipeline=$TRUE)]  
  34. [String] $Addr = "doctordns@gmail.com" ) 
  35. process { 
  36.    $s = new-webserviceproxy -uri http://www.webservicex.net/validateEmail.asmx 
  37.    foreach ($a in $addr) { 
  38.       $result = $s.IsValidEmail($a
  39.       $result 
  40.     } # end foreach 
  41. } #end process block 

No comments: