Showing posts with label Exchange Server 2016. Show all posts
Showing posts with label Exchange Server 2016. Show all posts

Apr 15, 2025

Windows 10/11 : Batch File to Start and Check Windows Services

Create a batch file to check the status of a Windows Service(s) and start it if its not started. The batch file can also be run inside "Task Scheduler" at an interval basis.


1. First, you need to find out the Service Name that you want to monitor, in this example let's say the service you need to monitor is an Exchange Server IMAP4 service.


2. Open --> Services and browse through the list until you found the IMAP4 service.


3. Right-click the Service Name --> Properties.


4. Take note of the "Service name:", copy the name to Notepad. As per below screenshot, the service name is "MSExchangeImap4".



5. Create a batch file as below :-


@ECHO OFF
CLS
SETLOCAL ENABLEDELAYEDEXPANSION
SET /A RETRY_IMAP=0
SET /A MAX_RETRIES=3
SET EXCH_IMAP= MSExchangeImap4

REM To check current status of the service.
:check_imap
SC QUERY %EXCH_IMAP% | FIND "RUNNING" >NUL
IF %ERRORLEVEL%==0 (
    ECHO Exchange IMAP4 Service is Running.
        GOTO end
)

REM To start the service if the status is stopped.
ECHO Exchange IMAP4 Service is Stopped.
SC START %EXCH_IMAP%
TIMEOUT /T 10 >NUL

REM To re-check the service status again for confirmation.
SC QUERY %EXCH_IMAP% | FIND "RUNNING" >NUL
IF %ERRORLEVEL%==0 (
    ECHO Exchange IMAP4 Service is Running.
        GOTO end
)

REM Retrying to start the service with a maximum of 3 retries only.
SET /A RETRY_IMAP+=1
IF !RETRY_IMAP! LSS %MAX_RETRIES% (
    ECHO Retrying Start %EXCH_IMAP% (Attemp: !RETRY_IMAP!).
    GOTO check_imap
) ELSE (
    ECHO Max Retries Reached for %EXCH_IMAP%, will stop retrying.
        GOTO end
)

:end
EXIT



6. You can now test run the batch file and create a "Task Scheduler" to run the check at an interval basis (eg. every 2 hours or at Startup of the server).



!!! HAPPY COMPUTING !!!

Dec 15, 2022

Exchange Server 2016 : Command Line

1. Get-ExchangeServer | Format-List Name,Edition,AdminDisplayVersion

2. Get-MailboxDatabase -Status | Select Name,LastFullBackup

3. Get-AuthConfig | fl CurrentCertificateThumbPrint

4. Get-ExchangeCertificate


Exchange Server 2016 : Outlook Search Not Working

 Microsoft Exchange Server 2016 : Outlook Search Not Working.

This issue happen when the "Content Index State" is either corrupted or incorrect.

1. Open --> Exchange Management Shell

2. Get-MailboxDatabaseCopyStatus * | sort name | Select name,status,contentindexstate

3. If the "Content Index State" = FailedandSuspended = Corrupted.

4. Stop-Service MSExchangeFastSearch

5. Stop-Service HostControllerService

6. Get-MailboxDatabase [DB Name] | select EdbFilePath

7. Open --> File Explorer --> Browse to [EDB Path] (eg. F:\Program Files\Microsoft\Exchange Server\V15\Mailbox\Mailbox Database)

8. Find a Sub-Folder with a GUID Name (eg. C5B6A9C4-DDA8-xxxx-xxx), DELETE the entire Sub-Folder.

9. Start-Service MSExchangeFastSearch

10. Start-Service HostControllerService

11. It will take some times to regenerate the index, be patient.

12. To check status --> Get-MailboxDatabaseCopyStatus * | sort name | Select name,status,contentindexstate

13. The status should either be "Crawling" = Work-in-Progress or "Healthy" = Good.


!!! HAPPY COMPUTING !!!