First import the user module:
Import-Module Microsoft.Graph.Users
Then connect to MgGraph
using your global administrator:
Connect-MgGraph -Scopes "User.ReadWrite.All"
Retrieve a list of licenseDetails objects for enterprise users.
Get-MgUserLicenseDetail -UserId $userId
Hope this helps.
If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.