D365FO – Enable maintenance mode in virtual machine

If you try to change a configuration setting in Microsoft Dynamics 365 for Finance and Operations in a virtual machine, you first need to switch to maintenance mode. And to be able to change a value, or to quickly disable the maintenance mode again I want to have a batch. Use the following batch script at your own risk, please adjust the settings to match your environment.
@ECHO OFF
REM Description: batch for enabling maintenance mode for Microsoft Dynamics 365 for Finance and Operations
REM Author: byteway
REM Date: 2 mei 2019
REM ---
SET MAINTENANCEMODE=%~1
SET EXE=C:\AOSService\PackagesLocalDirectory\Bin\Microsoft.Dynamics.AX.Deployment.Setup.exe
SET P1=metadatadir C:\AosService\PackagesLocalDirectory
SET P2=bindir C:\AosService\PackagesLocalDirectory\Bin
SET P3=sqlserver . 
SET P4=sqldatabase axdb 
SET P5=sqluser axdbadmin
SET P6=sqlpwd *********
SET P7=setupmode maintenancemode

IF /I "%MAINTENANCEMODE%" EQU "true" (
  SET P8=isinmaintenancemode true
  GOTO :SETMAINTMODE
)
IF /I "%MAINTENANCEMODE%" EQU "false" (
  SET P8=isinmaintenancemode false
  GOTO :SETMAINTMODE
)

GOTO :NOMAINTMODE 

:SETMAINTMODE
%EXE% --%P1% --%P2% --%P3% --%P4% --%P5% --%P6% --%P7% --%P8%
GOTO :END

:NOMAINTMODE
ECHO No maintenance mode found!
ECHO Syntax: "enable-maintenance-mode.bat [true | false]"
ECHO Example: enable-maintenance-mode.bat true
GOTO :END

:END
PAUSE