To overcome the problem of Exchange services not always starting up nicely I created a PowerShell script that can be run through a scheduled task. The script checks each of the Microsoft Exchange (MSExchange*) services that are set to automatic startup and verifies that they are properly running.
if ((Get-Service -Name MSExchangeADTopology).Status -ne "Running")
{
Start-Service -Name MSExchangeADTopology
}
do
{
foreach ($service in (Get-Service | Where-Object {$_.DisplayName -like "Microsoft Exchange*" -and $_.Status -eq "Stopped" -and $_.StartType -eq "Automatic"}))
{
Start-Service $service
}
}
while (Get-Service | Where-Object {$_.DisplayName -like "Microsoft Exchange*" -and $_.Status -eq "Stopped" -and $_.StartType -eq "Automatic"})
The above script starts off by verifying that the Microsoft Exchange Active Directory Topology has successfully started before proceeding to start the remaining services. Once all the remaining services have started the script will stop.
Once the script has been saved as a .ps1 file you run it on demand but this doesn't really address the need to start services in an unattended manner. This can be done through a scheduled task as outlined below:
- Launch Task Scheduler and
click on Create Basic Task
- Provide a Name to the task
and click Next
- Select a trigger, Daily
should be sufficient and click Next
- Select what time the task should run and
click Next
- Choose Start a program and
click Next
- Under Program/script
specify PowerShell and then put the full path to
the script in Add arguments
(eg. "C:\scripts\startexchangeservices.ps1")
then click Next
- Verify that everything looks correct and
click Finish
- Finally modify the properties of the task so
that it can run regardless of the user being
logged in or not as well as running with
administrative permissions.
Now that the script has been created and a task
has been setup to automatically verify that the
appropriate services have started lets take a look
at this in action. Here is an example from a freshly
rebooted machine and you can see there are a couple
Microsoft Exchange Services set to automatic that
don't have a status of started:
After the script runs we now see that the stopped
services are all running as expected: