Install SMTP Server and Telnet with PowerShell

This post has been republished via RSS; it originally appeared at: SharePoint Support Blog articles.



SharePoint and general app servers often use the SMTP Service to integrate e-mail into the systems functionality. Since Windows supports a well vetted SMTP Service, using the built-in application is often the best choice. With the said, when testing your app functionality with e-mail, Telnet is almost always needed and not installed by default.


If you find yourself always rebuilding servers to test new features and functionality, you may install SMTP and Telnet manually each time. If this is the case, why not use PowerShell?


What does the script do?


If SMTP is not installed, the installation will proceed. Once completed, it will then detect if Telnet is already installed. If not, you will be asked if Telnet should be installed. If you run the script a server with SMTP or Telnet already installed, the app installation will be detected and skipped.

I'm hoping this script will make your test builds quicker and more enjoyable in the future.


The Script:


# Check if SMTP is installed before installing it.
 $smtp = get-WindowsFeature "smtp-server"
 write-host "SMTP is not installed, installing it..." -ForegroundColor red
 add-WindowsFeature $smtp

 write-host "SMTP is already installed!" -ForegroundColor Cyan
 sleep 2

# Once SMTP is installed, prompt to install Telnet, if not installed.
 $telnet = get-WindowsFeature "telnet-client"

#Use a popup windows with a yes or no choice
 $shell = new-object -comobject "WScript.Shell"
 $choice = $shell.popup("Telnet is not installed, do you want to install it?",0,"Install Telnet",4+32)

 write-host "Telnet is already installed, done!" -ForegroundColor Green

#If you get here telnet is not installed and the user choose Yes.
 if ($choice -eq "6"){
 write-host "Installing Telnet..." -ForegroundColor Green
Add-WindowsFeature $telnet
 write-host "Done!" -ForegroundColor Cyan 

#If you got here telnet is not installed but the user chose No.
 if ($choice -eq "7" -and !$telnet.Installed){
 write-host "Telnet is not installed and will not be installed!" -ForegroundColor Green


The Output:


Here is what you will see if SMTP and Telnet is not installed:





Windows Popup asking if Telnet should be installed:




Installing Telnet:








If SMTP and Telnet is already installed it be detected and skip the installation:




REMEMBER: these articles are REPUBLISHED. Your best bet to get a reply is to follow the link at the top of the post to the ORIGINAL post! BUT you're more than welcome to start discussions here:

This site uses Akismet to reduce spam. Learn how your comment data is processed.