Q:

How to disable all optional modules in Magento 2.3?

I want to disable all third-party modules and Magento's optional modules, for example, DHL, Klarna, Temando, Vertex, etc.
I disabled via admin panel and CLI
There is a different way to exclude them?

A:

You can remove them via Composer.
You could install the Yireo module:
composer require yireo/magento2-replace-all:2.3.1

OR
You might be able to specify the packages to be removed in your composer.json and running composer update.
Examples
Remove all third-party core modules
"replace": {
        "amzn/amazon-pay-and-login-magento-2-module": "*",
        "amzn/amazon-pay-and-login-with-amazon-core-module": "*",
        "amzn/amazon-pay-module": "*",
        "amzn/amazon-pay-sdk-php": "*",
        "amzn/login-with-amazon-module": "*",
        "dotmailer/dotmailer-magento2-extension": "*",
        "dotmailer/dotmailer-magento2-extension-enterprise": "*",
        "klarna/m2-payments": "*",
        "klarna/module-core": "*",
        "klarna/module-kp": "*",
        "klarna/module-ordermanagement": "*",
        "temando/module-shipping-m2": "*",
        "vertex/product-magento-module": "*",
        "vertex/module-tax": "*",
        "vertex/sdk": "*"
    },

Remove all optional core modules
"replace": {
    "magento/module-advanced-pricing-import-export": "*",
    "magento/module-amqp": "*",
    "magento/module-analytics": "*",
    "magento/module-authorizenet": "*",
    "magento/module-braintree": "*",
    "magento/module-bundle-import-export": "*",
    "magento/module-catalog-analytics": "*",
    "magento/module-customer-analytics": "*",
    "magento/module-customer-import-export": "*",
    "magento/module-cybersource": "*",
    "magento/module-dhl": "*",
    "magento/module-downloadable-import-export": "*",
    "magento/module-eway": "*",
    "magento/module-fedex": "*",
    "magento/module-google-adwords": "*",
    "magento/module-google-optimizer": "*",
    "magento/module-grouped-import-export": "*",
    "magento/module-marketplace": "*",
    "magento/module-message-queue": "*",
    "magento/module-multishipping": "*",
    "magento/module-mysql-mq": "*",
    "magento/module-new-relic-reporting": "*",
    "magento/module-persistent": "*",
    "magento/module-quote-analytics": "*",
    "magento/module-release-notification": "*",
    "magento/module-review-analytics": "*",
    "magento/module-sales-analytics": "*",
    "magento/module-sample-data": "*",
    "magento/module-send-friend": "*",
    "magento/module-signifyd": "*",
    "magento/module-swagger": "*",
    "magento/module-swagger-webapi": "*",
    "magento/module-swagger-webapi-async": "*",
    "magento/module-swatches": "*",
    "magento/module-swatches-layered-navigation": "*",
    "magento/module-tax-import-export": "*",
    "magento/module-ups": "*",
    "magento/module-usps": "*",
    "magento/module-version": "*",
    "magento/module-wishlist-analytics": "*",
    "magento/module-worldpay": "*"
},

