Restarting the Exchange services:
Batfile
{Code]
@Echo Off
Echo 'Stopping Microsoft Exchange Services'
net stop MSExchangeAB
net stop MSExchangeADTopology
net stop MSExchangeAntispamUpdate
net stop MSExchangeEdgeSync
net stop MSExchangeFBA
net stop MSExchangeFDS
net stop MSExchangeIS
net stop MSExchangeMailboxAssistants
net stop MSExchangeMailboxReplication
net stop MSExchangeMailSubmission
net stop MSExchangeProtectedServiceHost
net stop MSExchangeRepl
net stop MSExchangeRPC
net stop MSExchangeSA
net stop MSExchangeSearch
net stop MSExchangeServiceHost
net stop MSExchangeThrottling
net stop MSExchangeTransport
net stop MSExchangeTransportLogSearch
Echo 'Starting Microsoft Exchange Services'
net start MSExchangeAB
net start MSExchangeADTopology
net start MSExchangeAntispamUpdate
net start MSExchangeEdgeSync
net start MSExchangeFBA
net start MSExchangeFDS
net start MSExchangeIS
net start MSExchangeMailboxAssistants
net start MSExchangeMailboxReplication
net start MSExchangeMailSubmission
net start MSExchangeProtectedServiceHost
net start MSExchangeRepl
net start MSExchangeRPC
net start MSExchangeSA
net start MSExchangeSearch
net start MSExchangeServiceHost
net start MSExchangeThrottling
net start MSExchangeTransport
net start MSExchangeTransportLogSearch
End
{/code}
Stooping the Exchange services
{Code}
@Echo Off
Echo 'Stopping Microsoft Exchange Services'
net stop MSExchangeAB
net stop MSExchangeADTopology
net stop MSExchangeAntispamUpdate
net stop MSExchangeEdgeSync
net stop MSExchangeFBA
net stop MSExchangeFDS
net stop MSExchangeIS
net stop MSExchangeMailboxAssistants
net stop MSExchangeMailboxReplication
net stop MSExchangeMailSubmission
net stop MSExchangeProtectedServiceHost
net stop MSExchangeRepl
net stop MSExchangeRPC
net stop MSExchangeSA
net stop MSExchangeSearch
net stop MSExchangeServiceHost
net stop MSExchangeThrottling
net stop MSExchangeTransport
net stop MSExchangeTransportLogSearch
End
{/code}
Starting the Exchange services
{Code}
@Echo off
Echo 'Starting Microsoft Exchange Services'
net start MSExchangeAB
net start MSExchangeADTopology
net start MSExchangeAntispamUpdate
net start MSExchangeEdgeSync
net start MSExchangeFBA
net start MSExchangeFDS
net start MSExchangeIS
net start MSExchangeMailboxAssistants
net start MSExchangeMailboxReplication
net start MSExchangeMailSubmission
net start MSExchangeProtectedServiceHost
net start MSExchangeRepl
net start MSExchangeRPC
net start MSExchangeSA
net start MSExchangeSearch
net start MSExchangeServiceHost
net start MSExchangeThrottling
net start MSExchangeTransport
net start MSExchangeTransportLogSearch
End
{/code}
Powershell:
Creating a powershell script to stop the exchange services is not so easy as i thought it would be. You could offcourse use the the Stop, restart and start-service cmdlet by specifying each and every echange service you wiched to start or stop, but this is as easaly done with the net stop/net start command. If we wish to gain any benefit from using powershell, we need to perform the same task, but with lesser code.
Stopping the Running Exchange Services is easy, but is only usefull when you wish to stop the Exchange services. Which would only occur in a planned maintenance window.
[Code]
Get-service -name "msexchange*" -dependentservices Where-Object {$_.Status -eq 'Running'} Stop-Service
[/Code]
Starting or restarting failed Exchange services proves to be a bit harder to configure, mainly because we do not want to start services which we do not need. If we would allow all Exchnage services to start, we would provide a larger attack surface than necessary (create a security hazard).
Starting all exchange services could be done by following code:
[Code]
Get-service -name "msexchange*" start-service
[/code]
But this is not recommended as it will start services as the imap4 and pop3 services as well. although not advisable the basis of the script could be extended with the exclude cmdlet in which we specify the services we wish to leave in a stopped state.
[Code]
get-setvice -name "msexchange*" -DependentServices -exclude msexchangepop3,msexchangeimap4,msexchangeMonitoring start-service
[/code]
this is definetly a usable peace of code, but still wondering if i can even shorten the code. one way of doing that would be by querying the msexchange services for it start-up type. In which we would query the services and only start services which have been set to start automatically.
In which we would specify following code:
[Code]
Get-Service -name "msexchange*" | where-object {$_.startuptype -eq "automatic"} start-service
[/code]
This peace of code will not work as "startuptype" is not a valid parameter with the get service cmdlet.
Powershell script:
This script get the status of the exchange services, and then asks if you wish to start them:
[Code]
Invoke-Command -ComputerName Exch02 {get-service -name msexchange*}
function ProcessAnswerY
{
Invoke-Command -ComputerName Exch02 {Start-Service -name msexchange* -exclude msexchangepop3, msexchangeimap4, msexchangemonitoring 2>&1}
}
function ProcessAnswerN
{
Write-Host "No Exchange services are altered"
}
$Choise = read-host "Type "y" to restart the Exchange services, press "N" to Quit"
& "ProcessAnswer$Choise"
[/code]
The script can be run remote when remote powershell is enabled on the Exchange Servers.
excellent! just what i was looking for! thanks for this!
ReplyDeleteThanks!
ReplyDeleteGood Information on Exchange services...
ReplyDeleteThank you
Zion
is there any other services that need to be started other than all the microsoft's services?
ReplyDeleteFrom an Exchange Point of view, yes. This does however does not consider other services that might be tied to the Exchange Services. An Example of this could be ForeFront For Exchange.
ReplyDeleteHi The Shrimp,
ReplyDeleteThanks for this post - really helpful.
One point though - many services depend upon the MSExchangeADTopology service, so this should be stopped last and started first, otherwise all sorts of mayhem ensues!
Hope this helps,
Rob H. - RGS IT Development.
not so helpfull because of bad order of services
ReplyDeleteOr you could restart the Microsoft Exchange Active Directory Topology service, and since it is depended on the others it will restart all of them. Much easier than a script.
ReplyDeleteOr you could restart the Microsoft Exchange Active Directory Topology service, and since it is depended on the others it will restart all of them. Much easier than a script.
ReplyDelete