6

Because of some error on my server, my SMTP service [SMTP Virtual Server #1] stops. I want to create job which will run periodically to check the SMTP server status, if it is stopped then the script will start it again.

I have used Start-Service "SMTPSVC" but it only starts the UATSERV service and not the [SMTP Virtual Server #1] virtual host (please have a look of the attached image).

How do I start the virtual server after the service is started?

My admin team is working on the issue. I wanted to use this temporary solution in the mean time.

Any help is appreciated... :)

SMTP virtual host image

Elliot Huffman
  • 1,229
  • 1
  • 12
  • 25
Optimus
  • 163
  • 1
  • 4
  • This doesn't actually work, at least in Windows 2008. It puts a Red X over the SMTP server but telnet tests to port 25 show that its not really working, at least not for me –  Aug 07 '14 at 07:56

2 Answers2

8

To Start:

$SMTP=[adsi]"IIS://localhost/SMTPSVC/1"
$SMTP.ServerState = 2
$SMTP.SetInfo()

To Stop:

$SMTP=[adsi]"IIS://localhost/SMTPSVC/1"
$SMTP.ServerState = 4
$SMTP.SetInfo()
Jenny D
  • 27,780
  • 21
  • 75
  • 114
  • By Mistake you are entered wrong ServerState for START & STOP the SMTP. – Optimus Feb 14 '13 at 06:39
  • ServerState 2 For START & ServerState 4 for STOP. Thanks Again.... – Optimus Feb 14 '13 at 06:40
  • fyi, this doesn't stop/start the server on windows 2012, it only changes the icon this worked for me: `$SMTP=[adsi]"IIS://localhost/SMTPSVC/1"` `$SMTP.Stop() or .Start()` – Rogelio Jul 04 '17 at 14:00
  • This did not work for me on Windows Server 2008R2. As above, the status appears to change in IIS Manager, but the actual status of the service is not affected. – andyb Oct 19 '17 at 23:59
  • As a heads-up, I found that the object does not "update" in PowerShell if the state is changed. For example, if `$SMTP.ServerState` is 2, then you use `$SMTP.Stop()` or stop it externally, then `$SMTP.ServerState` will STILL BE 2. You have to re-initialize `$SMTP` again to get the accurate state again. – Demonslay335 Apr 02 '19 at 14:41
1

Actual working answer is here:

([ADSI]'IIS://LOCALHOST/SMTPSVC/1').Start()
([ADSI]'IIS://LOCALHOST/SMTPSVC/1').Stop()

From: https://stackoverflow.com/a/37432396/3321505

andyb
  • 161
  • 6