Hi, you can use Microsoft Graph Data Connect
to extract user information from your M365 tenant, you can use the https://github.com/microsoftgraph/dataconnect-solutions/blob/main/datasetschemas/User_v1.md data set and there you can find the user ID and the licenses that are assigned to the user.
For additional information:
Microsoft Graph Data Connect (MGDC) provides Access to the M365 data at scale, while allowing administrators granular consent and full control over their Microsoft Graph data. Data Connect streamlines the delivery of this data to Microsoft Azure.
Here are some links:
Videos
Microsoft Graph Data Connect Demo and PBI Dashboards (YouTube video) https://www.youtube.com/watch?v=DiTYBWtzw2o
Webpage
Build your first Microsoft Graph Data Connect application https://learn.microsoft.com/en-us/graph/data-connect-quickstart?tabs=Microsoft365
Microsoft Graph Data Connect – Graph Data Analytics | Microsoft Azure https://azure.microsoft.com/en-us/services/graph-data-connect/
Overview of Microsoft Graph Data Connect (Microsoft Learn site) https://learn.microsoft.com/en-us/graph/data-connect-concept-overview
Datasets supported by Microsoft Graph Data Connect ((Microsoft Learn site) https://learn.microsoft.com/en-us/graph/data-connect-datasets