How do you automate exporting used licenses

Comp_tech 20 Reputation points

Hi everyone,

Does anyone know how to schedule exporting users with their used license type etc.? Looking into it scheduling it monthly and email it automatically if possible via PowerShell? Or do I need to set it on Power Automate?


Microsoft 365
Microsoft 365
Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line.
3,968 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
19,852 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous

    Hello! I'd be happy to help you with your question.

    You can use PowerShell to automate the process of exporting users with their used license type, and then schedule it to run monthly. Here are the steps you can follow:

    1. Install the Azure Active Directory PowerShell module on your computer.
    2. Open PowerShell as an administrator and connect to your Microsoft 365 tenant by running the command "Connect-MsolService".
    3. Run the following command to get a list of all users and their assigned licenses: "Get-MsolUser | Select-Object UserPrincipalName, DisplayName, UsageLocation, @{Name='Licenses';Expression={(Get-MsolUser -UserPrincipalName $_.UserPrincipalName).Licenses.AccountSkuId}}".
    4. Save the output to a CSV file using the "Export-CSV" cmdlet. For example: "Get-MsolUser | Select-Object UserPrincipalName, DisplayName, UsageLocation, @{Name='Licenses';Expression={(Get-MsolUser -UserPrincipalName $_.UserPrincipalName).Licenses.AccountSkuId}} | Export-CSV C:\export.csv -NoTypeInformation".
    5. Use Windows Task Scheduler to schedule the PowerShell script to run monthly.
    6. Optionally, you can use Power Automate to send the CSV file as an email attachment. You can use the "Get file content" and "Send an email" actions to accomplish this.

    I hope this helps! Let me know if you have any other questions.