In my job having access to a fully functional Exchange environment is highly beneficial as it allows me to test out various things in a non-production environment. Unfortunately this presents a bit of a challenge though as I need to balance out functionality as well as personal cost. Last summer after over a year of research I settled on using an older HP Z800 workstation for my lab that I was able to pick up at a reasonable price. The combination of this machine along with Hyper-V has provided me what I need with one small caveat, on under powered hardware Exchange services do not always start up nicely after reboots.

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:

  1. Launch Task Scheduler and click on Create Basic Task
    Scheduled Task
  2. Provide a Name to the task and click Next
    Scheduled Task Wizard 1
  3. Select a trigger, Daily should be sufficient and click Next
    Scheduled Task Wizard 2
  4. Select what time the task should run and click Next
    Scheduled Task Wizard 3
  5. Choose Start a program and click Next
    Scheduled Task Wizard 4
  6. 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
    Scheduled Task Wizard 5
  7. Verify that everything looks correct and click Finish
    Scheduled Task Wizard 6
  8. 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.
    Scheduled Task Wizard 7

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:
Services-Pre
After the script runs we now see that the stopped services are all running as expected:
Services-Post