You can run the below script to export all the distribution list members and owners (ManagedBy) to CSV file:
https://o365reports.com/2025/03/04/export-distribution-groups-report-in-microsoft-365/
To export all the mail-enabled security groups and their members, use the below script:
https://github.com/admindroid-community/powershell-scripts/blob/master/Microsoft%20365%20Group%20Report/M365GroupReport.ps1
By default, the script will list all the groups (DL, security, mail-enabled security, Microsoft 365 groups). You can filter mail enabled security groups by running the script as follows.
./M365GroupReport.ps1 -MailEnabledSecurity