How to enable SMTP server in Windows Server 2012

Ok, checking, adding and removing Windows components like this from the command line can be done via the powershell commands get-WindowsFeature, install-WindowsFeature, and to remove the feature afterwards remove-WindowsFeature.

To see if SMTP server is installed already use

get-WindowsFeature smtp-server

To install it use

install-WindowsFeature smtp-server

If you want a bit of re-usable code you can use everywhere to check if the SMTP server is already installed, and if not then install it then something like this ought to do it

smtp = get-WindowsFeature smtp-server
 if (!smtp.Installed) {
  $smtp | add-WindowsFeature
  }