Kaseya Community

Trying to create an elegant procedure to start Exchange 2010 & 2013 services after a reboot

This question is answered

We have found a problem with Exchange 2013 and on some 2010 servers that when they are rebooted certain services while report as being started, are not.

We have tried to create a procedure to run this command line option which works fine as a script or by starting Powershell Exchange Management Console and running the command: test-servicehealth | select-object -expand servicesnotrunning | start-service.

C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -command ". 'C:\Program Files\Microsoft\Exchange Server\V15\bin\RemoteExchange.ps1'; Connect-ExchangeServer -auto; c:\kworking\exchangehealthservice.ps1"

the exchangehealthservice script contains the following: test-servicehealth | select-object -expand servicesnotrunning | start-service

I have tried many variations including exshell.ps1 instead of remoteexchange and they both work at the command prompt while on the local machine.

I have tried using several of the various powershell script commands but just can't seem to get my desired results. The procedure does not fail, but there are no results as those services still fail.

I have removed powershell restrictions so I know that is not the problem.  Can someone guide me in my silly quest? One last note, how to I exit the powershell command at the end of  my test-servicehealth ps1 file so that powershell is ended?

Marc

Verified Answer
  • I just made two procedures that showcase two methods for interacting with Exchange via powershell.

    In your case I looked more closely and see you are putting your Exchange commands in a specific PS1 file and escape characters aren't actually an issue. The commands are very simple though and I don't think they need to be put in a dedicated PS1 file that you have to write down to the agent before executing -- you can run everything in one single step.

    Take a look at the examples in the Resoruces section linked here and you should be able to tweak them to run your test-servicehealth command (for some reason it didnt work on my old Exchange 2010 system):

    community.kaseya.com/.../86547.aspx


    I think you'll find method #2 which leverages the Exchange psconsole file is better.



    .
    [edited by: Ben at 6:11 PM (GMT -7) on Oct 14, 2014]
  • OMG, Thank you for your samples.

    I agree the ps1 file for the command string is not necessary. I used it to shorten my typing in the script to make viewing a bit easier. Using sample 1, I added the text commands to the Powershell Arguments and commands line and it worked Perfectly on Exchange 2013.

    I then changed the directory to V14 and using RemoteExchange.ps1 ran on an Exchange 2010 server and again, it worked Perfectly. I ran this several times, each time disabling an automated Exchange Service.

    I ran sample 2 without any modifications and did see the results in the Procedure Log. Did not try adding my changes because I wanted to run the script executingPowershellCommand. I will test sample 2 later to see if I can get the same great results.

    I am using this script to start the servers after a Server Reboot as a post reboot procedure in Patch Management-Reboot Action.

    Hope others can glean some valuable information from these examples.

All Replies
  • When you are chaining on extra filters you need to be mindful of using escape characters (^ in the case of the Windows command prompt) for special characters like |.  

    This applies to regular 'execute shell commands' and any powershell commands. It also applies to shell command steps executed in OS X and Linux -- in their case, the escape character is \, and the list of special characters you need to escape will be different than Windows.

    Especially with Exchange you also have to recognize that Exchange may not allow access by the 'system' account and you may need to run your commands in the context of a user that can authenticate to Exchange.

    If you need to feed some sort of 'exit' command you may be able to tack on something like '&& exit' at the end of your series of commands.

  • Thank you for such a quick response.. Should I be using "executeShellCommand" or executePowershellCommandxxBit...."

  • I just made two procedures that showcase two methods for interacting with Exchange via powershell.

    In your case I looked more closely and see you are putting your Exchange commands in a specific PS1 file and escape characters aren't actually an issue. The commands are very simple though and I don't think they need to be put in a dedicated PS1 file that you have to write down to the agent before executing -- you can run everything in one single step.

    Take a look at the examples in the Resoruces section linked here and you should be able to tweak them to run your test-servicehealth command (for some reason it didnt work on my old Exchange 2010 system):

    community.kaseya.com/.../86547.aspx


    I think you'll find method #2 which leverages the Exchange psconsole file is better.



    .
    [edited by: Ben at 6:11 PM (GMT -7) on Oct 14, 2014]
  • OMG, Thank you for your samples.

    I agree the ps1 file for the command string is not necessary. I used it to shorten my typing in the script to make viewing a bit easier. Using sample 1, I added the text commands to the Powershell Arguments and commands line and it worked Perfectly on Exchange 2013.

    I then changed the directory to V14 and using RemoteExchange.ps1 ran on an Exchange 2010 server and again, it worked Perfectly. I ran this several times, each time disabling an automated Exchange Service.

    I ran sample 2 without any modifications and did see the results in the Procedure Log. Did not try adding my changes because I wanted to run the script executingPowershellCommand. I will test sample 2 later to see if I can get the same great results.

    I am using this script to start the servers after a Server Reboot as a post reboot procedure in Patch Management-Reboot Action.

    Hope others can glean some valuable information from these examples.