Assign License to Microsoft 365 users using Powershell

Photo of author

To ensure that users can access Microsoft 365 services, it’s required to assign a relevant license, whether they are provisioned through Entra ID Connect or directly on Microsoft 365.

After a user account has been created on Microsoft 365, you can allocate the license, for example: Microsoft 365 E3 or Microsoft 365 Business Premium, based on the Microsoft 365 license subscription purchased.

Once a license has been assigned, resources will be provisioned in the background for the user. For example, An Exchange Online mailbox, OneDrive, etc.

Assign Microsoft 365 License using Powershell

Please follow below steps to assign a Microsoft 365 license to the user using Powershell:

  • Install and Import Exchange Online Powershell Module
  • Connect to Exchange Online ( EXO )
  • Connect to Entra ID
  • Export a list of users with their UPN information.
  • Then filter the list to find which users need to be assigned the licenses. Copy those users in a separate notepad. userprincipalname.txt file should only contain the UPNs e.g. as shown below

Userprincipalname.txt

[email protected] [email protected] [email protected]

  • Using the Product names and service plan identifiers page, Find out which license needs to be assigned to the users. Note down the license String ID.

For Example:

For Microsoft Entra ID P1, the String ID is AAD_Premium . We will use it to assign this license using Powershell.

  • Assign Microsoft Entra ID P1 to a User using below PowerShell command.
  • Assign Microsoft Entra ID P1 to bulk users. You can add UPNs of the users in a file called userprincipalname.txt and store it in C:\temp. Then run below powershell script to assign Microsoft Entra ID P1 to all those users.

How to assign License from Microsoft 365 admin center ?

You can follow below steps to assign Microsoft 365 license to the users from admin center.

  • Login on Microsoft 365 admin center
  • Click on Users > Active Users
  • Click on any user >  Click on Licenses and apps.
  • Use the checkbox next to the license to assign a license.

How to assign License from Microsoft 365 admin center?

Leave a Comment Cancel reply

Save my name, email, and website in this browser for the next time I comment.

Notify me of follow-up comments by email.

Notify me of new posts by email.

Photo of author

Detailed Step-by-Step guides for Setup/Troubleshooting/Configuration solutions on Intune, Microsoft 365, Powershell, Windows, Azure, and other Cloud technologies.

About the author Contact Us Privacy Policies Comment Policies Cookie Policies

Let's Connect!

Email Address

Assign a License to an Office 365 User with PowerShell

There are several scenarios where you might need to assign an Office 365 license to a user. The specific scenario in this blog article is that you're migrating an Exchange Server 2010 on-premises environment to Office 365. The Exchange Server is already in hybrid mode. Users have been automatically created in Office 365 by synchronizing them from your on-premises Active Directory environment using Azure AD Connect. Users who haven't already had their mailbox moved to Office 365 will first need an Office 365 license assigned to them, and before a license can be assigned to them, a usage location must be set on their individual account.

This blog article is written using Windows 10 Enterprise Edition version 1803 and Windows PowerShell version 5.1. The examples shown in this blog article will not work with PowerShell Core. Your mileage may vary with other operating systems and other versions of PowerShell.

First, you'll need the cmdlets to perform these actions. Find the MSOnline module in the PowerShell Gallery .

Install the MSOnline module from the PowerShell Gallery:

Store your Office 365 credentials with sufficient access to perform these tasks in a variable.

Connect to your Office 365 account. This is the part that will generate an error if you're using PowerShell Core.

Check to see if you have more than one Office 365 subscription.

Store the specific account SKU with the licenses for the Office 365 subscription to assign to users in a variable.

Find the users to assign licenses to and store them in a variable. I found it useful to narrow these results down by filtering left with the UserPrincipalName and/or Department parameters of Get-MsolUser .

As you can see in the previous image, John Doe does not currently have a license assigned.

Assign a usage location.

Assign an Office 365 license.

A license has now been assigned to John Doe.

Although a single user was assigned a license, with the exception of the previous command, the code as it is written in this blog article can be used to assigned licenses to multiple users.

Search code, repositories, users, issues, pull requests...

Provide feedback.

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly.

To see all available qualifiers, see our documentation .

  • Notifications

Jeff Brown Tech

Cloud and DevOps Engineering

Manage Office 365 License Using PowerShell

how to assign license office 365 powershell

Microsoft Office 365 licenses include many products and services – Exchange, SharePoint, Teams, etc. However, when organizations first adopt Office 365, many administrators deactivate some of these individual services. In this post, you will learn how to determine which Office 365 license services are disabled for a user and how to enable one or all of them using PowerShell.

For this tutorial, you will need:

  • Administrator access to your Office 365 tenant, such as Global Administrator or User Administrator
  • PowerShell version 7 (although 5.1 is also acceptable)

Connect to Microsoft Graph PowerShell

First, you need the Microsoft Graph PowerShell module to manage user licenses. To install this module:

  • Open a PowerShell console.
  • Run the following command to install the Graph module: Install-Module -Name Microsoft.Graph If you receive a warning about installing from an untrusted repository, enter Y and press Enter to continue the installation. If you receive a notification about requiring administrator rights to install the module, use the following command to install the module at the current user scope: Install-Module -Name Microsoft.Graph
  • Use the following command to connect to your tenant. The Scope parameter specifies the necessary graph permissions to perform user license administration. Connect-MgGraph -Scope Directory.AccessAsUser.All, Directory.ReadWrite.All

To learn more about getting started with the Microsoft Graph PowerShell module, check out Microsoft Graph PowerShell Module: Getting Started Guide !

View Office 365 Licenses

To view available Office 365 licenses in your tenant, use the Get-MgSubscribedSku command. Use Select-Object to focus on the SkuId and SkuPartNumber properties. You will need the SkuId later, and the SkuPartNumber describes the license type.

Get-MgSubscribedSku office 365 license powershell

The SkuPartNumber property describes what type of license it is. For example, ENTERPRISEPACK is the E3 license. For a complete list of product names and their string identifiers, check out this Microsoft Docs article .

Licenses consist of service plans, which are additional products or features included in the license. For example, the E3 or ENTERPRISEPACK license includes service plans for Exchange Online, SharePoint, Microsoft Teams, OneDrive, and others.

To view the service plans included in a license, use the Get-MgSubscribedSku command again with the All parameter. Use Where-Object to filter out the licenses based on SkuPartNumber , then select and expand the ServicePlans property. You will see the additional service plans included in the license and their current provisioning status.

get-mgsubscribedsku view license service plans

View User’s Assigned Licenses

Use the Get-MgUser command to view licenses currently assigned to a user account by viewing the AssignedLicenses property. When using the Get-MgUser command, use the Property parameter to specify returning the AssignedLicenses property as it is not in the default data return.

The following examples demonstrate various ways to retrieve the user’s assigned licenses. The first example returns the licenses, while the second example saves the results to a variable and then accesses them using dot notation.

View licenses assigned to a user account

In the screenshot above, only the SkuId is displayed, which is why it is helpful to view all the SKUs available in the tenant. You will need to match the SkuId assigned to the user from the subscribed SKUs in the tenant.

Assign Office 365 License using PowerShell

Use the Set-MgUserLicense command to assign a license to a user. Specify the licenses to add using the AddLicenses parameter with a hashtable consisting of the SkuId and value. You must also include the RemoveLicenses parameter with an empty array even if you are not removing licenses.

The example below adds the license Microsoft Power Automate Free license to the user account. This license has a SkuPartNumber of “FLOW_FREE” and a SkuId of “f30db892-07e9-47e9-837c-80727f46fd3d”.

Assign a License with Disabled Service Plans

Recall from earlier that a license includes service plans that provide access to different services or capabilities. You can also assign a license while turning off service plans.

First, use the Get-MgSubscribedSku command again and filter out which license you want to assign. This example assigns the E3 or ENTERPRISEPACK license.

Next, create a variable named $disabledPlans that filters off $e3.ServicePlans where ServicePlanName equals the services you wish to disable. The disabled plans in this example include Microsoft Bookings ( MICROSOFTBOOKINGS ) and Yammer ( YAMMER_ENTERPRISE ).

Hint: To find service plan names, go back to the View Available License section where you filtered and expanded the service plan information for a license.

Next, build a new license object variable that is an array with a single hashtable. The hashtable includes SkuId of the license you want to assign. You will also have a DisabledPlans key with a value of the $disabledPlans variable.

Finally, use the Set-MgUserLicense command again and assign the $addLicenses variable to the AddLicenses parameter. Again, don’t forget to include the RemoveLicenses parameter with an empty array.

Office 365 License and PowerShell Summary

In this tutorial, you learned how to install and connect to your tenant using the Microsoft Graph PowerShell module. You viewed the Office 365 license and service plans for a user account, and you enabled one or all service plans for a user, all using PowerShell!

Have you enjoyed this article? Check out more PowerShell articles here !

Related Post

Powershell scripting: getting started guide, powershell foreach: everything you need to know, azure automation managed identity: getting started.

  Windows OS Hub / Azure / Assigning User Licenses in Microsoft 365 (Azure AD) with PowerShell

Assigning User Licenses in Microsoft 365 (Azure AD) with PowerShell

You can manage Microsoft 365 user licenses on Azure Portal or with M365 Admin Center. Find a user in Azure AD and open the Licenses section. Here you can assign any of the available licenses to the user and select available products. In large companies, it is more convenient to manage Microsoft 365 licenses using PowerShell.

azure ad portal: user license assignments

To connect to Microsoft 365, use the Azure AD PowerShell module:

Connect-AzureAD

azure ad- available and assigned licenses

Using PowerShell, you can display information about available and assigned licenses in your Azure tenant as follows:

Get-AzureADSubscribedSku | Select -Property Sku*,ConsumedUnits -ExpandProperty PrepaidUnits

Get-AzureADSubscribedSku with powershell

SkuPartNumber is a name of a license (license plan). Enabled shows the number of licenses purchased under this plan. ConsumedUnits means the number of licenses assigned to the users.

You can use different Microsoft products under a license plan.

$licenses = Get-AzureADSubscribedSku $licenses[0].ServicePlans

powershell - get azure service plans

The ServicePlanName column shows the names of the products available to the users with this license.

You can display information about licenses assigned to a user. Get the SkuID of the license assigned to the user and then show its name:

$SkuIDs=(Get-AzureADUser -ObjectId [email protected] | Select -ExpandProperty AssignedLicenses).SkuId Foreach ($SkuID in $SkuIDs) { (Get-AzureADSubscribedSku | Where {$_.SkuId -eq $SkuID}).SkuPartNumber }

powershell: get azure license assigned to user

Get-AzureADUser -ObjectId [email protected] | Select UsageLocation, AssignedLicenses

If the country is not set or you have to change it, run the command below:

Get-AzureADUser -ObjectId [email protected] | Set-AzureADUser -UsageLocation DE

Then you can assign a license to a user:

$UserUPN=" [email protected] " $LicPlan="DEVELOPERPACK_E5" $License = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense $License.SkuId = (Get-AzureADSubscribedSku | Where-Object -Property SkuPartNumber -Value $LicPlan -eq).SkuID $assignlic = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses $assignlic.AddLicenses = $License Set-AzureADUserLicense -ObjectId $UserUPN -AssignedLicenses $assignlic Get-AzureADUserLicenseDetail -objectid $UserUPN

You can assign a license to multiple users at once. For example, let’s assign licenses to all users in the DE region:

To remove a license, use the PowerShell script below:

$userUPN=" [email protected] " $LicPlan="DEVELOPERPACK_E5" $license = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses $License.RemoveLicenses = (Get-AzureADSubscribedSku | Where-Object -Property SkuPartNumber -Value $LicPlan -EQ).SkuID Set-AzureADUserLicense -ObjectId $userUPN -AssignedLicenses $license

To display a list of unlicensed users, run this command:

Get-AzureAdUser | ForEach{ $licensed=$False ; For ($i=0; $i -le ($_.AssignedLicenses | Measure).Count ; $i++) { If( [string]::IsNullOrEmpty( $_.AssignedLicenses[$i].SkuId ) -ne $True) { $licensed=$true } } ; If( $licensed -eq $false) { Write-Host $_.UserPrincipalName} }

The following PowerShell script allows exporting the information about Azure users and licenses assigned to them into a CSV file. If no license is assigned to a user, “ Not Licensed ” will be specified for them in the report.

$Report = @() $users= Get-AzureAdUser Foreach ($user in  $users)  { $SkuIDs= @() $SkuIDs=(Get-AzureADUser -ObjectId $user.UserPrincipalName| Select -ExpandProperty AssignedLicenses).SkuId If ($SkuIDs -ne $null) { Foreach ($SkuID in $SkuIDs) { $License=(Get-AzureADSubscribedSku | Where {$_.SkuId -eq $SkuID}).SkuPartNumber $objReport = [PSCustomObject]@{ UPN = $user.UserPrincipalName DisplayName = $user.DisplayName Department = $user.Department License = $License } $Report += $objReport } } Else { $objReport = [PSCustomObject]@{ UPN = $user.UserPrincipalName DisplayName = $user.DisplayName Department = $user.Department License = "Not licensed" } $Report += $objReport } } $Report|Export-Csv c:\ps\aad_user_licenses.csv -Encoding UTF8 -NoTypeInformation

Generating Microsoft 365 (Azure) Licensing Report with PowerShell

It is hard and time-consuming to manage user licenses individually. In Azure AD, you can bind a license to an Azure group (group-based licensing). As soon as a user is added to the group, Azure assigns them a license automatically. However, you need an Azure AD Premium P1 subscription to use this feature. Also, the Azure AD module doesn’t allow to assign a license to a group. Group licensing features are available on Azure Portal or through the Microsoft Graph API .

How to Check .NET Framework Version Installed on Windows

Fix: screen brightness control not working on windows 10 or 11, related reading, unlocking active directory user accounts, how to find windows version and build number..., how to recall a sent email in outlook..., list and remove calendar events from exchange mailbox..., how to create a virtual machine on vmware..., leave a comment cancel reply.

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Current ye@r *

Leave this field empty

  • Programming & Development

Bulk assign Office 365 licenses with PowerShell

  • Microsoft Office 365

User avatar

  • Facebook Opens a new window
  • Twitter Opens a new window
  • Reddit Opens a new window
  • LinkedIn Opens a new window

Author Gregory for Microsoft

  • Microsoft Office 365 |
  • Microsoft Exchange |
  • Windows Server |
  • Active Directory & GPO |
  • Microsoft Office

This little PowerShell script I built will help you assign those Office 365 user licenses quickly and easily.

6 Steps total

Step 1: install ms office 365 sign on assistant.

http://www.microsoft.com/en-us/download/details.aspx?id=41950

Step 2: Install Azure AD PowerShell Module

http://go.microsoft.com/fwlink/p/?linkid=236297

Step 3: Find PowerShell and Right-Click Run As ISE

Right-click "run as ISE administrator", and then copy the PowerShell script provided below in step 4 into the scripts pane, and hit play / start.

Step 4: Create the CSV file

Either do this in Excel with a header named UserPrincipalName or you can use this script to create a dump of the UserPrincipalNames on Office 365 that are unlicensed currently.

Import-Module msonline Connect-MsolService Get-MsolUser -All -UnlicensedUsersOnly | Export-Csv c:\temp\licenses.csv

Open the CSV and add a header row at 1 called UserPrincipalName

Step 5: PowerShell Script

import-module msonline Connect-MsolService #CSV file picker module start Function Get-FileName($initialDirectory) { [System.Reflection.Assembly]::LoadWithPartialName(“System.windows.forms”) | Out-Null $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog $OpenFileDialog.initialDirectory = $initialDirectory $OpenFileDialog.filter = “All files (*.*)| *.*” $OpenFileDialog.ShowDialog() | Out-Null $OpenFileDialog.filename } #CSV file picker module end #Variable that holds CSV file location from file picker $path = Get-FileName -initialDirectory “c:\” #Window with list of available 365 licenses and their names $msolaccount = Get-MsolAccountSku | out-gridview -PassThru #Input window where you provide the license package’s name $AccountSKU = $msolaccount.AccountSkuId #CSV import command and mailbox creation loop import-csv $path | foreach { Set-MsolUser -UserPrincipalName $_.UserPrincipalName -usagelocation “US” Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -AddLicenses "$AccountSKU" } #Result report on licenses assigned to imported users import-csv $path | Get-MSOLUser | out-gridview

Step 6: Prompts

First Prompt is your Global Admin login for this particular Office 365 tenant.

Second Prompt is a CSV file with one column labeled UserPrincipalName (*Really just the email address) and the list of the users' email addresses you want to assign licenses to.

Third Prompt is the list of licenses available on your tenant and the number assigned / unassigned. With this prompt, the script does its thing, looping through each of the email addresses in the CSV file to get that license applied. This assumes the location is U.S., so change that bit in the code accordingly.

Fourth and last prompt is the user list from the CSV file, and whether the license is assigned or not.

There are many docs on how to do this, but nothing that gives you the ability to just click the license you wanted, without requiring a bit of fumbling to find the right SKU name. This script eliminates the stress when you have a ton of users to assign licenses to.

Good Luck and Happy Computing

  • Technet Bulk Assign Licenses Opens a new window

User avatar

Dolphinately going to use this! Thank you! Why couldn't microsoft allow more than ~10 users to be displayed at a time on the 365 admin page? So that we can PS of course.

User avatar

Very nice, we are jsut getting ready to start a migration and this looks like it will help immensly.

User avatar

Cracking! Will be using this in conjunction with my new user scripts. Thanks for sharing this.

User avatar

I figured out how to adjust this so I can remove the old license and add the new one in one step. Hooray! Thanks! This just saved me HOURS of work!

User avatar

I've found that the set-MsolUser command WILL assign the license, but it will NOT assign any of the APP's that the license grants. Meaning, a user will get an E3 assigned, but I still have to go into the O365 admin console and select all of the 30 apps corresponding to that particular license. How can we modify to assign the license, AND select all the apps?

how to assign license office 365 powershell

how to assign license office 365 powershell

Erwin Bierens

how to assign license office 365 powershell

Microsoft 365 - Assign licenses with PowerShell to users

During the working week i get a lot of questions about assigning licenses (mostly the Microsoft Teams Phone Standard license) to users in bulk. This can be easily resolved with PowerShell.

First logon to MSOnline, if you don’t have this module installed use: Install-Module -name MSOnline

Let’s see your active licenses

In order to assign a license to one of your users use the following cmdlet

In this example we’ve assigned the Microsoft Teams Phone Standard license to the user.

If you want to do this for multiple accounts you can do this by creating a script. First create a csv file with a column header: UPN List all accounts below with the UPN address who will need the license.

Save script below as Set-SKULicense.ps1 and change the $FilePath to the correct filename. Now just run the file and copy/paste the license in the prompt you want to assign.

Our Cloud Network

How To Assign User Licenses With Microsoft Graph PowerShell

  • Post author: Daniel Bradley
  • Post category: Microsoft 365 User Management / Microsoft Graph / Tutorials
  • Post last modified: May 19, 2023
  • Reading time: 11 mins read

Assigning Microsoft 365 licenses can be a tedious task, even with the bulk action tools in the Microsoft 365 admin center, when you are dealing with hundreds of users, it is not convenient.

Completing these simple but tedious tasks is always better using PowerShell and I definitely recommend it when dealing with hundreds of users, especially when the scripts you need are already available to you!

In this tutorial, we are going to look at how we can use Microsoft Graph PowerShell to assign and remove licenses from users in Microsoft 365.

Page Contents 

Pre-requisites

Using set-mguserlicense, find unlicensed users with filters.

  • Assign a user license using Set-MgUserLicense

Assign multiple licenses at the same time

  • Assign licenses to multiple users

Remove a single user license

Remove multiple licenses.

For this tutorial, you must have the Microsoft Graph PowerShell module installed. If you do not have it installed already, check out my guide on How To Install the Microsoft Graph PowerShell Module .

It is also necessary that you have enough available licenses to assign to your users. I have created a hand script here which will export a list of your available and used licenses using Microsoft Graph PowerShell.

The Set-MgUserLicense cmdlet can be found in the Microsoft.Graph.Users.Actions module, while the minimum level of permissions to use the command is Users.ReadWrite.All , you can also use the Directory.ReadWrite.All permission scope.

This information can be found by using Find-MgGraphCommand, we can also limit the results by selecting to display the ‘Module’ and ‘Permissions’ information.

Your output from the above command will look like the following. (you will see 2 results as it is displaying information for the standard (v1.0) profile and the beta profile.

Find-MgGraphCommand with Set-MgUserLicense

To begin, you may want to do a review of unlicensed user accounts in your tenant. To find unlicensed users you can apply a filter on the assignedlicenses property while using the Get-MgUser cmdlet. 

For example, to find all users where the license count is equal to 0, using the following command:

Bear in mind, this will find all unlicensed user accounts and if you have any dynamic groups that auto-assign free licenses in your tenant, this will not appear on your result.

Assign a user license with Set-MgUserLicense

First, we need to import the necessary modules into our PowerShell session and connect to Microsoft Graph with the necessary permissions.

Now we are connected, we need the ID of the license SKU that we want to assign. We can work this out by running the Get-MgSubscribedSku cmdlet.

From the output, you will see a list of all available licenses as well as the SkuId which we will need when we use the Set-MgUserLicense cmdlet.

Get-MgSubscribedSku

From here, we can store our target license in a variable, below we store the information of our E5 Developer license in the $license variable.

Another thing we also need to know is the object id of our target user. For this, we use a similar tactic for storing our user information in a variable. Below we are storing the user information of ‘Adele Vance’ in the $user variable.

We can now use our variables with the Set-MgUserLicense cmdlet with the -UserId and -AddLicense parameters.

You may notice I have also defined the -RemoveLicenses parameter with an empty value. Without defining the -RemoveLicenses parameter you will get the following error:

Set-MgUserLicense : One or more parameters of the operation ‘assignLicense’ are missing from the request payload. The missing parameters are: removeLicenses.

Below is the full script so you can copy and paste it!

The -AllLicenses parameter also enables you assign multiple licenses at the same time, by added mutiple licenses to a hash table. There are a couple of ways we can acheive this… 

F irstly, we can take all of the licenses assigned to a single user (as a template) and assign these to another user. Start by using the Get-MgUserLicenseDetail cmdlet to store assigned license to a variable.

We then need to build an array of hastables which we can include in our Set-MgUserLicense command.

Let’s look at what we have done, here is the before and after:

Before

You can see from the above that before we had a list of objects for each license, but after we have an array of hastables containing the key value pairs for each license. This is what we need to include in our command to assign mulitple licenses to a user or users.

There are different ways you can create your hashtable, in some instances it may be easier to manually create your hashtable array in the event you plan on assigning specific licenses to mulitple users. For example:

How to assign a license to multiple users with Microsoft Graph PowerShell

To assign a license to multiple users, we first have to store our users and loop through them using the ForEach command.

Your users can be obtained in multiple ways, you can either use the Get-MgUser cmdlet to define your user list, of which you will be able to simply obtain the necessary user attributes for the script. 

Or if you already have a CSV containing your user list, you could import the CSV and then obtain the user id from within the loop.

Here is an example where I store a list of users based on them containing ‘@ourcloudnetwork.com’ in their mail attribute, then I assign each user a DEVELOPERPACK_E5 license.

Or if you want to perform the same task, but this time, use an existing list of users you have saved in a CSV, you can use the below script.

When removing a single user license, the -RemoveLicenses parameter does not expect a hashtable, but instead just the SkuId  string of the license. For example, to remove a single license from a user, we can use the below command:

We can see that this command is succesful while only providing the the SkuId string value in the parameter.

License SkuId

The concept is similar for removing multiple licenses at once, compared to adding multiple licenses. We can define an array of SkuId values into the command to remove multiple licenses.

Like before, there are multiple way to create your array, you can either define it manually within your script or create it based on the values of an existing user or any available licenses.  

For example, to create an array list of specific SkuId’s, you can use the below:

The array will look like the following:

Multiple SkuIds

This array can then be included in your command as follows to remove the specified licenses from a single user. 

You can use the previous example for running this command against mulitple users in your oganisation. 

Post author avatar

Daniel Bradley

You might also like.

Read more about the article How to Configure Microsoft Intune to Manage Your Workstations

How to Configure Microsoft Intune to Manage Your Workstations

Bulk delete azure ad groups from azure ad with powershell.

Read more about the article What is Microsoft 365? A Complete Overview

What is Microsoft 365? A Complete Overview

This post has 12 comments.

how to assign license office 365 powershell

Hi daniel and everyone i need an alternate command for bulk license removal and assignment in PowerShell for microsoft365 because below commands is not working after depreciation of Azure PS and MSol PS

$licencetoremove = “pern:STANDARDWOFFPACK_STUDENT” import-csv “D:\student-uoh.csv” | ForEach-Object { Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -RemoveLicenses $licencetoremove}

$licencetoadd = “pern:M365EDU_A3_STUUSEBNFT” import-csv “D:\student-uoh.csv” | ForEach-Object { Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -AddLicenses $licencetoadd}

how to assign license office 365 powershell

Check out the information at the bottom of the post, you can use this for bulk license removal! 🙂

how to assign license office 365 powershell

Thank you. This is very handy as I try to migrate some of my scripts away from Azure AD and MSOL. I am getting hung up on using an existing CSV of users to assign licenses. Your ForEach loop references a specific account: (Get-MgUser -UserId [email protected] ).Id, rather than a variable.

To work around this I set up a variable $licUser = $users.UserPrincipalName then modified your line to be $userid = (Get-MgUser -UserId $licUser).Id

This is working great if I only have one user in my CSV but I’m seeing errors:

Get-MgUser : Cannot process argument transformation on parameter ‘UserId’. Cannot convert value to type System.String. At line:5 char:31 + $userid = (Get-MgUser -UserId $licUser).Id

Here is my complete snippet of code, not sure if you could offer any suggestions

$UsageLocation = “US” #sets location to US $licUser = $users.UserPrincipalName

ForEach ($user in $users) { Write-host “Assigning licenses to $($user.DisplayName)” $userid = $null $licUser = $users.UserPrincipalName $userid = (Get-MgUser -UserId $licUser).Id Update-MgUser -UserId $userid -UsageLocation $UsageLocation Set-MgUserLicense -UserId $userid -AddLicenses @{SkuId = ($E3FACSku.SkuId)}, @{SkuId = ($E3EMSSku.SkuId)}, @{SkuId = ($FLOWSku.SkuId)}, @{SkuId = ($PAPPSSku.SkuId)} -RemoveLicenses @() }

Well, never mind. I tried it a different way and got it working:

$Users | ForEach-Object { Update-MgUser -UserID $_.UserPrincipalName -UsageLocation $UsageLocation Set-MgUserLicense -UserID $_.UserPrincipalName -AddLicenses @{SkuId = ($E3FACSku.SkuId)}, @{SkuId = ($E3EMSSku.SkuId)}, @{SkuId = ($FLOWSku.SkuId)}, @{SkuId = ($PAPPSSku.SkuId)} -RemoveLicenses @() }

$users being from the .csv I imported.

I didn’t think I could use -UserId with $_.UserPrincipalName — I thought they’d be too completely different values.

#powershellnovice

Good job on figuring it out! I was away from my desk when I saw this comment pop up! There are some scenarios where using the USERNAME with -UserId does not pull complete information and the ID needs to be used instead. But that is just another nuance of Microsoft Graph PowerShell..!

how to assign license office 365 powershell

Hi Dahieil, awesome guide by the way. Been following through your guide but I can’t seem to get things through.

I have a csv list of email address with header “email” import it with the comman below

$users = Import-Csv C:\changelicense\batch01.csv #-Delimiter “;”

for the loop this is what I’m doing adding yours in between.

ForEach ($email in $users) { Write-host “Assigning license to $($email)” $userid = $null $userid = (Get-MgUser -UserId $email).Id Set-MgUserLicense -UserId $userid -AddLicenses @() -RemoveLicenses @{SkuID =’xxxx’} Set-MgUserLicense -UserId $userid -AddLicenses @() -RemoveLicenses @{SkuID =’xxxx’} Set-MgUserLicense -UserId $userid -AddLicenses @{SkuID =’xxxxx’} -RemoveLicenses @() }

but I keep getting this error below. Would you happen to understant what I’m missing? please done mind the SkuID I just replaced them with xxxx

Get-MgUser : Resource ‘@{ [email protected] }’ does not exist or one of its queried reference-property objects are not present. At line:4 char:5 + $userid = (Get-MgUser -UserId $email).Id + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: ({ UserId = @{em…ndProperty = }:f__AnonymousType10`3) [Get-MgUser_Get1], RestException`1 + FullyQualifiedErrorId : Request_ResourceNotFound,Microsoft.Graph.PowerShell.Cmdlets.GetMgUser_Get1 Set-MgUserLicense : Cannot bind argument to parameter ‘UserId’ because it is an empty string. At line:5 char:31 + Set-MgUserLicense -UserId $userid -AddLicenses @() -RemoveLicense … + ~~~~~~~ + CategoryInfo : InvalidData: (:) [Set-MgUserLicense], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,Set-MgUserLicense

If your CSV has a header of Email , then when you loop through each item in the collection, you would need to user $email.email to extract the value from the property.

For example: $userid = (Get-MgUser -UserId $email.email).Id

how to assign license office 365 powershell

This script works for me:

The input file has this column with 2 entries. EmployeeID test5 test6

$Path = “\\fileservices\IT\Scripts\Email creation scripts\agents.csv” $users = Import-Csv -Path $Path

# Assigns (Microsoft F3) with the almost all services turned off for users in bulk $UsageLocation = “MX” #sets location to MX $DESKLESSsku = Get-MgSubscribedSku -All | Where SkuPartNumber -eq ‘DESKLESSPACK’ $disabledPlans = $DESKLESSsku.ServicePlans | ` Where ServicePlanName -in (“SHAREPOINTWAC”,”YAMMER_ENTERPRISE”,”MICROSOFTBOOKINGS”,”SWAY”,”POWERAPPS_O365_S1″,”PROJECT_O365_F3″,”KAIZALA_O365_P1″,”SHAREPOINTDESKLESS”,”BPOS_S_TODO_FIRSTLINE”,` “OFFICEMOBILE_SUBSCRIPTION”,”PROJECTWORKMANAGEMENT”,”VIVA_LEARNING_SEEDED”,”WHITEBOARD_FIRSTLINE1″,”STREAM_O365_K”,”MCOIMP”,”POWER_VIRTUAL_AGENTS_O365_F1″) | ` Select -ExpandProperty ServicePlanId

$addLicenses = @( @{ SkuId = $DESKLESSsku.SkuId DisabledPlans = $disabledPlans } )

$users | ForEach-Object { $UserPN = (Get-ADUser -Identity $_.Employeeid).UserPrincipalName Update-MgUser -UserId $UserPN -UsageLocation $UsageLocation Set-MgUserLicense -UserId $UserPN -AddLicenses $addLicenses -RemoveLicenses @() }

how to assign license office 365 powershell

Hello David son, I see that you are from Mexico, will it be possible for me to contact you to see if you can help me with some of the script and CSV?

I am open to direct messages on LinkedIn if you want to message me there.

how to assign license office 365 powershell

Hi ! on using this it asks me to sign in to MS account, I am using the account with License Administrator role but it seems its enough for this: Connect-MgGraph -Scope User.ReadWrite.All

All I want to do is to assign some license, do you have any idea?

Hey Faraz, you will be able to do this, but you’ll first need a Global Administrator to consent to the permission.

Simplest solution is to ask your Global Admin to run Connect-MgGraph -Scope User.ReadWrite.All and click consent. Then you can run Connect-MgGraph 🙂

Leave a Reply Cancel reply

Save my name, email, and website in this browser for the next time I comment.

how to assign license office 365 powershell

Bulk Assign Licenses in Office 365 Using PowerShell

If you manage an Office 365 tenant, you are probably familiar with assigning licenses to provision services for users. That process is pretty straightforward for a single user.

But how do you do it for a hundred or thousand people in your organization? PowerShell.

First, you will need to connect to Office 365 via PowerShell. If you haven’t done this before,  follow these steps to install the prerequisites.

To connect to O365/MSOnline, use the following command:

Import-Module MSOnline Connect-MsolService

You will be prompted for credentials – this needs to be a user with at least user management role permissions, but most operations in this module will require global admin permissions.

Next, you will need to get a list of licenses available in your tenant. This can be viewed easily in the admin portal under Billing, but is identified by the AccountSkuID in PowerShell. To generate a list of what is available and assigned, run the following command:

Get-MsolAccountSku

The results will contain your tenant name and sku and looks something like this:

If you’re using E1/E3 licenses, they will have a name like “tenantname:ENTERPRISEPACK” or “tenantname:STANDARDPACK”.

Now that you know what you have available to assign, you need to determine which users will be assigned a license. This can be a difficult task, especially in larger organizations.

If you’re lucky enough to just assign all users in your tenant a license, your process will be relatively simple. Prior to assigning licenses, you must assign a location. This is a required field and is done by country. This will essentially provision the Exchange Online mailbox in the proper region and ensure that it follows all local laws, etc.

To assign the US location to a single user, you would use the following command:

Set-MsolUser [email protected] $upn -UsageLocation US

All countries follow the 2-letter ISO code standard –  a list of those can be found here .

Now, we’re using PowerShell – we want to actually  bulk assign licenses and locations, not just do single users. To assign the US location to all of your tenant users, use the following command:

Get-MsolUser -All | Set-MsolUser -UsageLocation US

To verify the results, use the following command:

Get-MsolUser -All | Select DisplayName,UsageLocation

Once the location is assigned either through the admin portal or PowerShell, you can assign licenses. The following command would assign an E3 license to all users in the US only:

Get-MsolUser -All -UsageLocation ‘US’ | Set-MsolUserLicense -AddLicenses “tenantname:ENTERPRISEPACK”

There are several other properties that may be useful in narrowing down the scope of users to bulk assign licenses to. Use the following command to view only users that do not have a license assigned:

Get-MsolUser -UnlicensedUsersOnly

This command will assign licenses only to users with a specific domain name:

Get-MsolUser -All -DomainName ‘pagosa.ai’ | Set-MsolUserLicense -AddLicenses “tenantname:ENTERPRISEPACK”

A full list of properties to use with Get-MsolUser   can be found here .

What if it isn’t this straightforward in your organization? You may have several countries, types of licenses, or maybe you want to assign licenses in batches. Sometimes it’s just easiest to assign both the location and license at the same time from a CSV file – this is usually the preferred method in larger organizations. This operation can be done with a simple PowerShell script ( download it here ):

The above script references users in a CSV file containing users’ UPN, location, and license to assign. It looks like this ( download it here ):

You will need to modify the script to use the correct path to the CSV file.

If you need to generate a list of users in your O365 tenant, including their UPN, location, and whether or not a license is currently assigned, you can use the following command:

Get-MsolUser | select-object DisplayName,UserPrincipalName,UsageLocation,IsLicensed

Your results will look similar to this:

To export the same data to a CSV file, add a bit more to the end:

Get-MsolUser | select-object DisplayName,UserPrincipalName,UsageLocation,IsLicensed | export-csv C:\pathtofile\o365export.csv -notype

how to assign license office 365 powershell

Assigning licenses for Office 365 users using PowerShell

The following is a comparison between adding licenses to Office 365 users with Windows PowerShell and ADManager Plus

Windows PowerShell

Steps to manage licenses of office 365 users using powershell:.

  • Identify the Office 365 tenant from which you want to retrieve the report.
  • Identify the cmdlets you need to fetch the report.
  • Compile the script.
  • Execute it in Windows PowerShell.

Sample Windows PowerShell script:

Admanager plus, steps to add licenses for office 365 users:.

  • Select Office 365 -> License Management ->Assign/Remove licenses
  • Select Add licenses option, choose the desired license(s), and User Location from the drop down list.
  • Choose the Office 365 account and its users, and click Apply.

Assign Office 365 Licenses to Users in Bulk using ADManager Plus

» Start 30-day Free Trial

Following are the limitations to manage licenses of Office 365 users using native tools like Windows PowerShell:

  • With additional filters, the script will get longer and more complicated.
  • Troubleshooting these scripts requires extensive AD and scripting expertise.

ADManager Plus can help you assign licenses of Office 365 users in a simple and intuitively designed UI.

Assign or remove Office 365 licenses for multiple accounts in one go with ADManager Plus.

  • Embark on your script-free AD management, reporting, and automation journey with ADManager Plus.
  •    
  • By clicking ' Start your free trial now ', you agree to processing of personal data according to the Privacy Policy .
  • Your download should begin automatically in 15 seconds. If not, click here to download manually.

Related Powershell How-to Guides:

For AD User Management

  • Create new user accounts in AD using Powershell
  • Import Active Directory users from CSV using PowerShell
  • Add new user in AD using Powershell
  • Modify AD user attributes using Powershell
  • Enable Active Directory user accounts using PowerShell
  • Disable AD accounts using PowerShell
  • Delete user accounts in AD using Powershell
  • Move AD user accounts using Powershell
  • Remove users from Active Directory group using PowerShell
  • Set expiration Date for AD Accounts using Powershell
  • Modify AD Account Control Values using Powershell
  • Unlock AD accounts using Powershell
  • Modify AD Objects using Powershell
  • Set AD accounts to never expire using Powershell
  • Add proxy address to AD user with Powershell Scripts

For AD User Reporting

  • Get all AD users report using Powershell
  • Get active/inactive AD user accounts using Powershell
  • Export enabled AD users report using Powershell
  • Get disabled users report in AD using Powershell
  • Get active directory account status reports using PowerShell
  • Find locked AD user accounts using Powershell
  • Find account expired users in AD using Powershell
  • Get last logon time of AD user accounts using Powershell
  • List AD user accounts set to never expire with Powershell
  • Find specific users in AD using Powershell
  • Get AD User information with their managers using Powershell
  • Get AD user samaccountname using Powershell
  • Get AD users' list from multiple OUs using Powershell
  • Get AD Users' list along with their Display Names
  • Get a list of AD users that belong to a Specific Department
  • Get a list of AD users with empty attributes using Powershell
  • Get a list of AD Users having a Specific CN using Powershell

For GPO Management

  • Create GPO using Powershell
  • Create and remove GPO links using PowerShell
  • Edit GPO using Powershell
  • Generate GPO report using Powershell
  • View Unlinked GPO using Powershell
  • Get GPOs List using Powershell
  • Get GPO Link Report using Powershell
  • Backup and restore GPO using Powershell

For Password Management

  • Change password for AD users using PowerShell
  • Find AD user's last password changed date using PowerShell
  • Set password for AD accounts using Powershell
  • Set AD user must change password at next logon with PowerShell
  • Set AD user password to never expires using Powershell
  • Get password expired users list using Powershell
  • Get users with soon-to-expire passwords using Powershell
  • Get AD Users' List whose passwords never expire using Powershell
  • Get Password Expiration Date of AD Users using Powershell

For AD Group Management

  • Create Active Directory groups using Powershell
  • Add users to Active Directory groups using Powershell
  • Add a group as a member of another AD Group using Powershell
  • Add principal group membership for AD users using Powershell
  • Modify AD group attributes using PowerShell scripts
  • Delete Active Directory groups using Powershell
  • How to remove a group from another group in AD using PowerShell
  • Create dynamic distribution groups using Powershell
  • Create distribution groups using Powershell
  • Add multiple members to distribution groups using PowerShell
  • Group membership report in AD using Powershell
  • Get membership details of a specific AD user using Powershell
  • Get AD Group members of a specific group using powershell

For File Access Management

  • Set and modify folder permissions in Active Directory
  • Detect file and folder permissions in AD using Powershell
  • Export user's file and folder access permissions using Powershell
  • Get permissions of all AD objects using Powershell
  • Get ACL for folders and subfolders using Powershell
  • Get NTFS permissions using Powershell

For AD Computer Management

  • Create AD Computer accounts using PowerShell
  • Modify AD Computer attributes using PowerShell
  • Enable AD Computer accounts using PowerShell
  • Disable AD Computer accounts using PowerShell
  • Move AD Computer accounts using Powershell
  • Remove AD Computer accounts using PowerShell
  • Find inactive AD Computer accounts using PowerShell
  • Find AD Computer's last logon time using Powershell
  • List Computers in an AD Domain using Powershell

For Office 365 Management

  • Guide to Connect to Office 365 Powershell Module
  • Add users to Office 365 groups using PowerShell
  • Assign license to Office 365 users using PowerShell
  • Change Office 365 user licenses using Powershell
  • View all Office 365 licenses in your account using Powershell
  • Remove Office 365 license from user accounts using Powershell
  • Office 365 users license report using Powershell
  • Get all Office 365 group members using Powershell
  • Dynamic distribution group members report using Powershell
  • Dynamic distribution groups report using Powershell

For Exchange Management

  • Quick Guide to Connect to Exchange Online PowerShell
  • Create Mailboxes in Exchange Online with Powershell
  • Remove mailboxes from Exchange Online using Powershell
  • Export Exchange Online distribution groups list using PowerShell
  • Create Mailboxes in Exchange Servers with Powershell
  • Remove user mailboxes from Exchange Server using Powershell
  • Export Distribution Group Members Report using PowerShell

For Other AD Tasks

  • Guide to install and import PowerShell active directory module
  • Sync AD objects using PowerShell
  • Add Exchange PowerShell module
  • Active Directory Health Check using Powershell
  • Active Directory Cleanup using Powershell
  • Create OU in Active Directory using Powershell
  • Modify OU settings using Powershell
  • Get Bitlocker Recovery Keys using PowerShell
  • List all Active Directory servers using PowerShell
  • Get a list of OUs in AD using PowerShell
  • Move AD objects using Powershell
  • Search for an AD account using Powershell
  • Get AD domain information using Powershell
  • Modify an Active Directory domain using PowerShell.

The one-stop solution to Active Directory Management and Reporting

  • AD Management
  • Exchange Management
  • Related Products
  • Active Directory Management
  • Active Directory Reports
  • MS Exchange Management
  • Bulk User Management
  • Active Directory User Reports
  • AD Helpdesk Delegation
  • Active Directory Group Management
  • AD Logon Reports
  • Active Directory Automation
  • Active Directory Cleanup
  • Distribution List Reports
  • ADManager Plus Mobile Apps
  • Office365 Management
  • Office 365 User Provisioning
  • Office 365 Reports
  • Bulk User Creation
  • Password Management
  • Helpdesk Delegation
  • Bulk Group Management
  • Computer Management
  • GPO Management
  • Identity orchestration
  • User Logon Reports
  • AD User Reports
  • Password Reports
  • Folder Access Reports
  • Group Reports
  • Computer Reports
  • AD Last Logon Reports
  • Exchange Reports
  • Disable/Delete Exchange Mailbox
  • Exchange Mailbox Migration
  • Set Mailbox Rights
  • Exchange Mailbox Creation
  • Office 365 Management
  • Office 365 Reporting
  • Office 365 License Management
  • Office 365 License Reports
  • Office 365 User Reports
  • Office 365 Group Reports
  • Office 365 Automation
  • Office 365 Mailbox Management
  • Integrated Identity and Access Management Solution
  • Unified SIEM Solution
  • UBA-driven AD and Windows Server Auditing Solution
  • Identity Security Solution with MFA and SSPR
  • Real-time Log Management and IT Compliance Solution
  • Hybrid Exchange Auditing and Reporting Solution
  • File Auditing and Data Leak Prevention Solution
  • Microsoft 365 Management and Reporting Solution
  • Enterprise Backup and Recovery Solution
  • SharePoint Management and Auditing Solution
  • Cloud Security and Log Management Solution
  • FREE Active Directory Tools
  • All Windows Active Directory Solutions
  • Download  
  •   Live Demo
  •   Free Edition
  •   Get Quote
  •   Buy Now

Subscribe for Practical 365 updates

Please turn off your ad blocker and refresh the page to subscribe.

You may withdraw your consent at any time. Please visit our Privacy Statement for additional information

Microsoft 365 / Microsoft Entra ID / PowerShell

Including costs in a microsoft 365 licensing report.

Avatar photo

Table of Contents

Know How Much User License Costs Are and How Much Unassigned Licenses Absorb

The articles I’ve written about using the Microsoft Graph PowerShell SDK to create a tenant licensing report are very popular. The October 2021 article laid the foundation and explains the basics of extracting licensing information for Entra ID user accounts. Two years later, the follow-up article describes how to add support for group-based license assignments. I now want to address a common request and add support for cost reporting for both individual users and the tenant.

Few like to rewrite code. I am no different. With that in mind, I decided to make as few changes as possible when incorporating the new code to report license costs. Apart from anything else, this means that people who used the previous versions of the script to create their own licensing report should find it easier to update their version. At least, that’s the plan.

Licenses and Subscriptions

As a refresher, let’s cover the basics of Microsoft 365 licensing. Tenants pay for licenses through subscriptions. A subscription is for a product like Microsoft 365 E3. Some subscriptions are free, either unlimited or for a trial period. Subscriptions have unique SKU identifiers. The Get-MgSubscribedSku cmdlet returns the details of current subscriptions for a tenant.

Paid subscriptions have an associated monthly cost that differs from country to country in accordance with local taxation and other factors. For instance, the monthly cost for Office 365 E3 is $23 in the U.S. and EUR23.10 ( without Teams ) in Ireland. Because of its complexity, I don’t attempt to handle multi-country pricing here. The script assigns the same price to all licenses for an SKU.

how to assign license office 365 powershell

Including Costs with License Subscription Data

Get-MgSubscribedSku tells us what subscriptions exist in a tenant. It doesn’t tell us anything about the price. I use a script ( downloadable from GitHub ) to take the CSV file published by Microsoft on the licensing and service plan reference page and use it to build CSV files containing subscription and service plan information. The data includes ‘friendly names’ for subscriptions and service plans to allow the script to report those names instead of GUIDs. By loading the data into hash tables, the script can quickly translate a GUID (like 06ebc4ee-1bb5-47dd-8120-11324bc54e06) to a product or service plan name (in this case, Microsoft 365 E5).

To add costs to the equation, I edit the CSV file holding SKU information so that the line for each product includes a price column. I then insert the price that I pay for each license into that column. Companies are free to negotiate prices with Microsoft and the cost paid for a subscription depends on how successful that negotiation is.

I also inserted a currency column, but only populate this column for the first product (because the script uses the same currency everywhere). Figure 1 shows what the SKU information CSV file looks like for my tenant.

License subscription information with costs.

To make the pricing information quick to access, the script reads the CSV file and creates a hash table comprising key-value pairs of the SKU identifier (key) and the monthly price (value).

Calculating License Costs

Previous versions of the script create an array of licenses (direct and group-based) assigned to user accounts. Calculating the cost of the licenses assigned to individual user accounts is a matter of:

  • Computing the annual cost for a license (monthly cost * 12).
  • Adding the annual cost for each license to compute the total cost.

The script does this in a simple PowerShell function. You can see that all prices are reckoned in cents to accommodate prices like $17.70 or EUR16.40.

Reporting License Costs

Before the script processes any user account, it checks if pricing information is available. It does this by checking the Price column for the first product in the SKU list. The script also fetches the currency (string prefix) from the currency column. If this data is available, the $PricingInfoAvailable variable is set to true to control whether the script computes cost information for assigned licenses and includes this in the output report. If the variable is false, no pricing information is included.

Figure 2 shows an example of the licensing report with cost information. The costs of all licenses assigned to a user appears under “Annual License Costs.”

License assignment report with annual costs per user.

After reporting data for all users, the report includes some summary information (Figure 3) including the total cost for each subscription (annual cost multiplied by number of licenses). You could cut and dice this information multiple ways. For instance, you could compute an annual cost for users in each country, each office, or each department.

I do like being able to compute an overall percentage of used license costs. Right now, my tenant spends $13,212. However, the cost of assigned licenses is $12,024, so my license assignment effectiveness is only 91.01% and Microsoft receives $1,188 annually for unused licenses.

License cost summary for a Microsoft 365 tenant.

Of course, this is test data, and I certainly do not leave that amount on the table for Microsoft to add to the $134.8 billion annual run rate for the Microsoft Cloud announced in Microsoft’s FY24 Q2 results.

Update: V1.6 of the script includes cost analyses by country and department. This article explains the code changes necessary to implement these features.

Not a License Cost Management Solution

It’s important to say that the script (which you can download from GitHub ) is not a full-fledged license cost management solution. Instead, it’s a demonstration of how to access and use the license information available to tenants. Because the code is PowerShell, it’s easy to amend to suit specific requirements. If anyone finds an issue, please log it in GitHub. Better again, fix the problem and create a pull request so that everyone benefits from your contribution.

Preparing for a Transition from Active Directory to Azure AD

TEC Talk: Preparing for a Transition from Active Directory to Azure AD

About the Author

Avatar photo

Tony Redmond

' src=

Hi! This script is great!!! Just having an issue with anything to do with the cost :), as I’m getting US $ 0.00 everywhere :/. Any ideas?

Have you included any currency information in the SKU CSV file?

' src=

Hi Tony, Very helpful script. How can I get Microsoft365LicensesReport.html as excel? Also like to know if I can get Microsoft365LicensesReport.html with filtering option.

The script generates a CSV file that can be loaded into Excel. If you want to generate a workbook, update the script to use the ImportExcel module. https://office365itpros.com/2022/05/10/importexcel-powershell/

The PSWriteHTML module is a good way of generating a HTML file with filtering options. See this article for an example: https://office365itpros.com/2022/07/20/sharepoint-external-users-report/

' src=

Hi Tony, I Love the update. Is there a way to break the costs down even further for departments as well? We have multiple departments in our tenant and would like to look at costs for each department as well. Any thoughts or ideas would be appreciated. My basic thought is…. Department name | Total licensed Users | Total Department Cost … All of the data is there; I just don’t know how to group and total it and then add it to the output report.

This should be very easy. Give me a couple of days and I will look at updating the script.

I published a new version (1.6) of the script which includes analyses by department and by country. The steps required to generate this data are explained in this article: https://office365itpros.com/2024/02/14/microsoft-365-licensing-report/

Leave a Reply Cancel reply

Latest articles.

Exchange 2019 CU14 Fixes Exploits in the Wild

Exchange 2019 CU14 Fixes Exploits in the Wild

Microsoft released cumulative update 14 for Exchange Server 2019 on February 13, 2024. This update fixes several bugs, but more importantly, contains a fix for a serious security issue that is being exploited in the wild. This is your sign to enable Extended Protection, if you haven't already.

The Critical Need for Integrating Devices with Intune 

The Critical Need for Integrating Devices with Intune 

In this blog, Jon Jarvis reviews the importance of integrating devices with Intune, and the risks that can arise from poorly managed devices.

Microsoft Releases Public Preview of Microsoft 365 Backup

Microsoft Releases Public Preview of Microsoft 365 Backup

If you’re interested in protecting your SharePoint Online, OneDrive for Business, or Exchange Online data, it is useful to understand how Microsoft 365 Backup works and what the software can and cannot do. In this article, Paul Robichaux walks through how to set up and test the preview version of Microsoft 365 Backup.

  • Microsoft 365

how to assign license office 365 powershell

How to Delete Folders with PowerShell Remove-Item

Deleting folders and cleaning up directories can be a time-consuming task, especially when you need to perform the same task on multiple computers. With PowerShell, we can easily create a small script to find and delete all the folders you want.

The advantage of PowerShell is that it allows us not to only delete a single folder, but complete directories or only folders with a specific name. It’s also possible to delete only empty folders for example.

In this article

In this article, we are going to take a look at how to delete folders with PowerShell, and how to use the different options to delete only specific folders.

Delete Folders with PowerShell

To delete folders with PowerShell we will need to use the Remove-Item cmdlet. This cmdlet can not only be used to delete folders, but also for removing files , registry keys, and more. We will focus on deleting folders in this article.

The Remove-Item cmdlet comes with a couple of parameters that we can use to specify the folder that we want to remove:

To delete a single folder in PowerShell, we will need to specify the full path to the folder. Good to know is that this command will delete the folder with all contents in it, even if you haven’t specified the -recurse parameter. You will get a warning though if you haven’t used the -recurse parameter and the folder contains content.

So it’s important that you check if you have the correct folder before you actually delete it. That is why I recommend to run the command first with the -WhatIf parameter to check the result:

In the example below, the folder wasn’t empty. So we will need to confirm that we want to delete the folder and the content.

The last line, What If, shows which operation is performed on the target path:

powershell delete folders

Instead of -WhatIf we can also force the confirm prompt. This way you can still double-check if you are deleting the correct folder and confirm the action before it’s deleted.

Delete Folder and Contents

When you want to delete a folder and all its contents with PowerShell, then you must use the -Recurse parameter. This way all subfolders, and files in the given directory will be removed. The parameter won’t give a warning, it will just remove all the contents.

The command below will delete “Folder A” and the contents of it:

If you only want to delete all the content that is inside “folder A”, then we must use a wildcard inside the -path parameter:

Force Delete Folder

When you try to delete a folder that contains read-only items or items that are in use, you will get an error message that you do have not sufficient access rights to perform this operation.

powershell remove folder

To delete a folder that contains a read-only item, hidden files, or files that are in use, you can use the -Force parameter:

Delete Multiple Folders

To delete multiple folders with a single command we can either specify multiple paths or use one of the filtering options. I will explain filters later in this article. You can specify multiple folders to delete by using a comma-separated string:

Another option is to create an array with all the paths and loop through them with a foreach statement.

Delete Folder if Exists

When using the Remove-Item cmdlet inside scripts, it’s a good idea to test if the folder exists before you try to delete it. We can do this by using the  Test-Path cmdlet . This will check if the folder exists and return true or false based on the result. By using this inside an if statement we can make sure that the folder is only deleted if it exists:

Using Filters to Delete Folders in PowerShell

We have now looked at the basic principles to delete a folder with PowerShell. But besides deleting a folder from a specific path, you often encounter situations where you need to delete all folders that are older than x days or contain a specific word in the folder name.

There are a couple of methods to select only the folders that we need to remove in PowerShell. But with all methods, make sure that you test the selection first before you actually delete the folders.

Using the Include Filter

The -include filter allows you to specify a part of the string that the file or folder must contain that you want to delete. It works in combination with the wildcard character in the path.

Important to note here is that both files and folders are deleted that contain the given name. For example, to delete all folders (and thus also files) that have the word test in them:

You can also specify multiple keywords for the include filter, simply separate them with a comma.

Using the Exclude Filter

With the -exclude filter, we can delete all the contents in a specific folder, except folders that have a specified word in the name. Again, the filter works on both files and folders, so all files that match the filter as well won’t be removed.

For example, to remove all files and folders from the specified path, except the contents in the folder “la-test-folder”, we can do:

Just like with the include filter, you can use a wildcard in the exclude string, or specific multiple strings (folder names) to match.

Delete Folders older than

A situation that is quite common is to delete all folders that are older than x days. To do this we will first need to calculate the folder date. Let’s say we want to delete all folders that are older than 30 days. The first step is to get the date from 30 days ago:

The next step is to get all the folders in the given path that are older than the given date. We can do this by comparing the lastwritetime of the folder with the datetime that we calculated:

We now only have to pipe the Remove-Item cmdlet behind it to actually delete the folder and its contents. Again first test the results with the -WhatIf parameter before actually deleting the folders.

Remove Empty Folders

To remove only empty folders with PowerShell you will need to create a small script. The script will need to check for each subfolder in the given folder if it contains items or not. When it doesn’t contain any items only then can the folder be deleted.

I created a script that you can use the remove empty folders, you can find the script in this article .

Wrapping Up

PowerShell is a great tool when you need to delete multiple folders or want to clean up a particular directory automatically. Keep in mind that the Remove-Item cmdlet is also used to delete files, so make sure you test your scripts before using them.

Also, keep in mind that your files are deleted permanently, they won’t go to the recycle bin.

I hope you found this article useful, if you have any questions, just drop a comment below.

You may also like the following articles

Connect MgGraph

How to use Connect-MgGraph – All Options

install powershell 7

How to Install PowerShell 7 Quickly

powershell set env var

How to Set an Environment Variable in PowerShell

Leave a comment cancel reply.

Notify me of followup comments via e-mail. You can also subscribe without commenting.

how to assign license office 365 powershell

This browser is no longer supported.

Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.

Set-Msol User License

Updates the license assignment for a user.

The Set-MsolUserLicense cmdlet is deprecated. Learn how to assign licenses with Microsoft Graph PowerShell . For more info, see the Assign License Microsoft Graph API.

Description

The Set-MsolUserLicense cmdlet updates the license assignment for a user. This can include adding a new license, removing a license, updating the license options, or any combination of these actions.

Example 1: Add a license to a user

This command adds the Office 365 for Enterprises license to the user.

Example 2: Remove a license from a user

This command removes the Office 365 for Enterprises license from the user. This may result in the user's data being removed from each service.

Example 3: Replace one license with another

This command replaces the Office 365 for Enterprises license with an Office 365 Deskless license. These changes are made in one single operation. Therefore, the user does not end up in an intermediate state where the Office 365 for Enterprises license is removed without Office 365 Deskless being added.

-AddLicenses

Specifies an array of licenses to assign to the user.

-LicenseOptions

Specifies an array of license- or SKU-specific settings. Used to disable individual services when assigning a license.

Specifies the unique object ID of the user for which to update licenses.

-RemoveLicenses

Specifies an array of licenses to remove from the user.

Specifies the unique ID of the tenant on which to perform the operation. The default value is the tenant of the current user. This parameter applies only to partner users.

-UserPrincipalName

Specifies the user principal name of the user to update.

Related Links

  • Set-MsolUserPassword
  • Set-MsolUserPrincipalName

Additional resources

Export Microsoft 365 users last sign-in date and time

  • Updated on February 21, 2024
  • Microsoft 365

You can get the user’s last successful sign-in activity date time in the Microsoft Entra admin center and Microsoft 365 admin center. The disadvantage is that it will show the user’s sign-in activity for the last 7 days. In this article, you will learn how to export Microsoft 365 users last sign-in date and time with Microsoft Graph PowerShell.

Table of contents

Microsoft 365 user last sign-in activity date, get single microsoft 365 user sign-in logs, get all microsoft 365 users sign-in logs, connect to microsoft graph powershell, export microsoft 365 users last sign-in activity report with powershell, get single microsoft 365 user last sign-in activity date time, export all microsoft 365 users sign-in activity report csv file.

When a user signs into a Microsoft product, it will save this information to their sign-in activity. If you have the Microsoft Entra ID Free license, you can only check the last sign-in activity for the past 7 days for a Microsoft 365 user.

Last sign-in activity date vs. Last successful sign-in activity date:

  • Last sign-in activity: It shows the last time a user signs in with their username and password (success or failure) .
  • Last non-interactive sign-in activity: It shows the last time a user signs in without using their username and password (success or failure) .
  • Last successful sign-in activity: The last time a user signs with their username and password and succeeds .

The table below shows the different methods available with a Microsoft Entra ID license Free .

Note: To view the last sign-in activity over 7 days, you need a Microsoft Entra ID P1 or P2 edition license.

The table below shows the different methods available for a Microsoft Entra ID P1/P2 license .

*The data will start recording sign-ins after December 1, 2023, because the property is new.

Note: In the Microsoft admin centers, the last sign-in activity of the users updates instantly, but with PowerShell, the last sign-in activity will appear in the report after 6 hours.

We will show you how to export a single and all Microsoft 365 users last sign-in date and time in:

  • Microsoft Entra admin center
  • Microsoft Graph PowerShell

Get Microsoft 365 users sign-in activity in Microsoft Entra ID

Microsoft Entra admin center saves the last sign-in logs of all the Microsoft 365 users for the past 30 days. We will show you how to check and export the last sign-in activity for a single and all Microsoft 365 users.

Microsoft Entra ID shows these types of sign-ins for the users:

  • Interactive sign-ins: Sign-ins are done by the user who signs in with their username and password or MFA, such as the Microsoft Authenticator app.
  • Non-interactive sign-ins: Sign-ins done on behalf of a user , such as a client app that doesn’t require MFA authentication from the user. For example, if the user signed in before, it will save the login for next time, so they don’t need to provide their username and password or MFA.

To get a single Microsoft 365 user sign-in activity in Microsoft Entra ID, follow these steps:

  • Sign in to Microsoft Entra admin center
  • Expand Identity > Users > All users
  • Click on a specific user

Export single Microsoft 365 user sign-in activity report in Microsoft Entra ID

  • Click Sign-in logs
  • Click the tab User sign-ins (interactive)

The list of all the interactive sign-ins with the date and time of the last 24 hours appears by default. If you can’t find any sign-in logs, you should change the date to the last 1 month and click apply .

Sign-in logs single user sign-ins interactive in Microsoft Entra ID

  • Click the tab User sign-ins (non-interactive)

The list of all the non-interactive sign-ins with the date and time of the last 24 hours appears by default. If you can’t find any sign-in logs, you should change the date to the last 1 month and click apply .

Sign-in logs single user sign-ins non-interactive in Microsoft Entra ID

To export all Microsoft 365 users sign-in activity in Microsoft Entra ID, follow these steps:

A list of all the users’ sign-ins with the date and time of the last 7 days appears by default. You can always change the date, but it can only show you the sign-ins for the last month.

Users interactive sign-in logs in Microsoft Entra ID

A list of all the users non-interactive sign-ins with the date and time of the last 7 days appears by default. You can always change the date, but it can only show you the sign-ins for the last month.

Users non-interactive sign-in logs in Microsoft Entra ID

To export the sign-in activity of Microsoft 365 users longer than 1 month, you must use PowerShell in the next step.

Before you start, you must Install Microsoft Graph PowerShell module , including the Microsoft Graph Beta module.

Run the below command to install the Microsoft Graph modules.

Important: Always install the Microsoft Graph PowerShell and Microsoft Graph Beta PowerShell modules. That’s because some cmdlets are not yet available in the final version and will not work. Update both modules to the latest version before you run a cmdlet or script to prevent errors and incorrect results.

Then you need to Connect to Microsoft Graph PowerShell with the below scopes.

You are set to use the cmdlets with Microsoft Graph PowerShell in the next steps.

We will show you the steps to export Microsoft 365 users last sign-in activity report to a CSV file with PowerShell.

It will gather the following information per user:

  • UserPrincipalName
  • DisplayName
  • AccountEnabled
  • LastSuccessfulSignInDate
  • LastNonInteractiveSignInDateTime
  • LastSignInDateTime
  • DaysSinceLastSuccessfulSignIn

Create the temp folder in your (C:) drive if you don’t have them already.

Get Microsoft 365 user last sign-in activity with PowerShell

When looking at the users last sign-in activity date and time, you will find these properties in PowerShell:

  • LastNonInteractiveSignInDateTime: The last non-interactive sign-in (success or failure) date and time for a specific user. In PowerShell it shows the Microsoft Entra ID non-interactive sign-ins from May 2020.
  • LastSignInDateTime: The last interactive sign-in (success or failure) date and time a user attempted. In PowerShell it shows the Microsoft Entra ID interactive sign-ins from April 2020.
  • LastSuccessfulSignInDateTime: The last successful interactive date and time a user signs in with a password. In PowerShell it shows the last successful sign-in date from December 2023.

To get a single user last sign-in activity, you need to use their Object ID .

Run the below PowerShell command to get the last sign-in activity of a single user.

If you don’t have the user Object ID , you can use the UserPrincipalName with the below PowerShell command.

The PowerShell output shows the last sign-in date time and the last successful sign-in date time for a single user.

Get all the users (including members and guests) last successful sign-in activity report and export it to an Out-Gridview and CSV file.

Run the below PowerShell script to export a full report of all the users last sign-in date and time.

The Out-GridView appears, where you can search and filter the properties.

Export Microsoft 365 users sign-in date and time report to Out-GridView

Open the CSV file with an application like Microsoft Excel to see the same results.

Export Microsoft 365 users sign-in date and time report to CSV file

Did it help you to get the last login time of all Microsoft 365 users to a CSV file?

Read more: Bulk create Microsoft 365 users with CSV file »

You learned how to export Microsoft 365 users last sign-in date and time. This can be done in Microsoft Entra admin center or PowerShell. The Microsoft Entra admin center shows the users last interactive and non-interactive sign-in logs for the last 30 days. A better method is to use Microsoft Graph PowerShell to export a report of all the users sign-in activity because it will show results for more than 30 days.

Remember that you have limitations with a Microsoft Entra ID Free license, and you need a Microsoft Entra ID P1/P2 license to get the maximum out of it.

Did you enjoy this article? You may also like Bulk import contacts to Microsoft 365 using PowerShell . Don’t forget to follow us and share this article.

o365info Team

o365info Team

This article was written by our team of experienced IT architects, consultants, and engineers.

What Others Are Reading

Microsoft 365

Your organization has already set up SPF and DKIM, so the last step is configuring…

If you send an email within the Microsoft 365 organization, you can recall the message…

The Focused Inbox will replace the Clutter feature in Outlook. It places your most important…

This Post Has 0 Comments

Leave a reply cancel reply.

Your email address will not be published. Required fields are marked *

  • previous post: How to Assign Microsoft 365 licenses with PowerShell

IMAGES

  1. Microsoft Office Tutorials: Assign licenses to users in Office 365 for

    how to assign license office 365 powershell

  2. How to assign bulk license in Microsoft 365 using powershell

    how to assign license office 365 powershell

  3. Powershell Script to Assign License for Office 365 Users #powershell

    how to assign license office 365 powershell

  4. Office 365 License Reporting and Management using PowerShell

    how to assign license office 365 powershell

  5. Assign Windows 365 License with PowerShell and MS GRAPH API

    how to assign license office 365 powershell

  6. Assign Windows 365 License with PowerShell and MS GRAPH API

    how to assign license office 365 powershell

VIDEO

  1. Assign Office 365 License to User step by step

  2. Office 365 interview questions and answers #shorts #shortsfeed #youtubeshorts #interview #career

  3. Microsoft 365

  4. របៀប Share license office 365 free

  5. How to manage Office 365 using PowerShell and the space race

  6. Create Users through Powershell in Microsoft Office 365

COMMENTS

  1. Assign Microsoft 365 licenses to user accounts with PowerShell

    First, connect to your Microsoft 365 tenant. Assigning and removing licenses for a user requires the User.ReadWrite.All permission scope or one of the other permissions listed in the 'Assign license' Microsoft Graph API reference page. The Organization.Read.All permission scope is required to read the licenses available in the tenant. PowerShell

  2. How to Assign Microsoft 365 licenses with PowerShell

    Expand Identity > Users > All users Select the user Click Licenses on the left pane or at the bottom Click Assignments Select licenses

  3. Assign License To Microsoft 365 Users Using Powershell

    Please follow below steps to assign a Microsoft 365 license to the user using Powershell: Install and Import Exchange Online Powershell Module 1. Install-Module -Name ExchangeOnlineManagement 2. Import-Module ExchangeOnlineManagement Connect to Exchange Online ( EXO) Connect-ExchangeOnline -UserPrincipalName <UPN> Connect to Entra ID

  4. Assign a License to an Office 365 User with PowerShell

    Get-MsolAccountSku powershell Figure 5: o365-assignlicense5a.png Store the specific account SKU with the licenses for the Office 365 subscription to assign to users in a variable. $LicenseSKU = Get-MsolAccountSku | Out-GridView -Title 'Select a license plan to assign to users' -OutputMode Single | Select-Object -ExpandProperty AccountSkuId

  5. Assign Microsoft 365 licenses to user accounts with PowerShell

    You can use PowerShell to quickly assign licenses to unlicensed accounts.</p>\n<p dir=\"auto\">User accounts must first be assigned a location.

  6. Manage Microsoft 365 user accounts, licenses, and groups with PowerShell

    Create user accounts View user accounts Configure user account properties Assign roles to user accounts Delete and restore user accounts Block user accounts Passwords Licenses and services View licenses and services View licensed and unlicensed users Assign licenses to user accounts View account license and service details

  7. Assign or unassign licenses for users in the Microsoft 365 admin center

    You can assign or unassign licenses for users in the Microsoft 365 admin center on either the Active users page, or on the Licenses page. The method you use depends on whether you want to assign or unassign licenses for specific users, or assign or unassign users for a specific product. Note

  8. Manage Office 365 licenses with PowerShell

    Get-Command -Noun *MSOL*. Listing Office 365 cmdlets. This command returns all MSOnline module cmdlets. You can also list the number of cmdlets in the module with this command: (Get-Command -Noun *MSOL*).count. Total count of Office 365 cmdlets. Now we are ready to manage Office 365 licenses with PowerShell.

  9. Manage Office 365 License Using PowerShell

    Assign Office 365 License using PowerShell Assign a License with Disabled Service Plans Office 365 License and PowerShell Summary Connect to Microsoft Graph PowerShell First, you need the Microsoft Graph PowerShell module to manage user licenses. To install this module: Open a PowerShell console.

  10. Use PowerShell to Create and Assign Licenses to Office 365 Users

    In the PowerShell window, run the following command and press ENTER: In the pop-up window, enter your Office 365 tenant credentials, and click OK. This will authorize you to...

  11. Managing Office 365 Licenses with the Azure AD V2 PowerShell Module

    Assigning a Single License Using PowerShell Assigning Multiple Licenses Using PowerShell Assigning Licenses with Sub-SKU Features Disabled Removing Licenses Using PowerShell The Azure AD V2 PowerShell Module License management in Office 365 is performed using the Azure Active Directory PowerShell module.

  12. Manage Microsoft 365 Licenses with the Microsoft Graph PowerShell SDK

    Assign a New Microsoft 365 License The most basic operation is to assign a license to an Azure AD account using the Set-MgUserLicense cmdlet. You need to know: The UPN or object identifier of the target Azure AD account. The SKU identifier of the product you wish to license for the account.

  13. Assigning User Licenses in Microsoft 365 (Azure AD) with PowerShell

    Here you can assign any of the available licenses to the user and select available products. In large companies, it is more convenient to manage Microsoft 365 licenses using PowerShell. To connect to Microsoft 365, use the Azure AD PowerShell module: Connect-AzureAD. You can find a list of available licenses in Azure AD -> Licenses -> All products.

  14. Bulk assign Office 365 licenses with PowerShell

    Bulk assign Office 365 licenses with PowerShell - Spiceworks Join Home Programming & Development PowerShell How-tos Read these next... Load More This little PowerShell script I built will help you assign those Office 365 user licenses quickly and easily.

  15. How to Use PowerShell to Automatically Assign Licenses to Your Office

    The SetupScript.ps1 will create the required subdirectory strucuture, prompt for O365 admin credentials and will generate the Powershell scripts AssignLicense.ps1, Get-LicensingInputFromAD.ps1 and Get-MSOLUserLicensingReport.ps1. It will also prompt your for a DefaultUsageLocation, which is required in Office 365 for a license assignment.

  16. View Microsoft 365 licenses and services with PowerShell

    First, connect to your Microsoft 365 tenant. Reading subscription license plans requires the Organization.Read.All permission scope or one of the other permissions listed in the 'List subscribedSkus' Graph API reference page. PowerShell Connect-Graph -Scopes Organization.Read.All

  17. Office 365 Licenses and PowerShell

    Now, let's dive into the specific PowerShell commands used to view and manage Office 365 licenses. First, you need to connect to Microsoft Graph PowerShell using the following CmdLet: Connect-MgGraph -Scopes Directory.Read.All,User.Read.All. This command assumes you have already installed the Microsoft Graph PowerShell module.

  18. Microsoft 365

    First logon to MSOnline, if you don't have this module installed use: Install-Module -name MSOnline. In order to assign a license to one of your users use the following cmdlet. Set -MsolUserLicense -UserPrincipalName [email protected] -AddLicenses tenant:mcoev. In this example we've assigned the Microsoft Teams Phone Standard license to the ...

  19. How To Assign User Licenses With Microsoft Graph PowerShell

    Get-MgUser -Filter 'assignedLicenses/$count eq 0' -ConsistencyLevel eventual -CountVariable CountVar -All Bear in mind, this will find all unlicensed user accounts and if you have any dynamic groups that auto-assign free licenses in your tenant, this will not appear on your result. Assign a user license with Set-MgUserLicense

  20. Bulk Assign Licenses in Office 365 Using PowerShell

    September 13, 2016 If you manage an Office 365 tenant, you are probably familiar with assigning licenses to provision services for users. That process is pretty straightforward for a single user. But how do you do it for a hundred or thousand people in your organization? PowerShell. First, you will need to connect to Office 365 via PowerShell.

  21. Bulk Assign Licenses to Office 365 Users using powershell

    Identify the Office 365 tenant from which you want to retrieve the report. Identify the cmdlets you need to fetch the report. Compile the script. Execute it in Windows PowerShell. Click to copy entire script. Steps to add licenses for Office 365 users: Select Office 365 -> License Management ->Assign/Remove licenses.

  22. Reporting User License Costs for a Microsoft 365 Tenant

    This article describes how to include user license costs in a Microsoft 365 tenant licensing report created with the Microsoft Graph PowerShell SDK. The report includes annual costs for all licenses assigned to each user plus an overall licensing summary for the tenant. ... For instance, the monthly cost for Office 365 E3 is $23 in the U.S. and ...

  23. Assign Microsoft 365 licenses to user accounts

    To assign Microsoft 365 licenses to individual user accounts, you can use: The Microsoft 365 admin center PowerShell The Microsoft Entra admin center Group-based licensing You can configure security groups in Microsoft Entra ID to automatically assign licenses from a set of subscriptions to all the members of the group.

  24. MS365 Apps for enterprise Last Activated Date

    for my company I'm prototyping an C# or Powershell Application to remove unused licences which may have been overlooked by the offboarding process for an employeer. We are using AD-Groups to assign a license, if AD-User gets included in the AD-Group, an Office 365 E3 (Service "Microsoft 365 Apps for Enterprise") licence will be assigned to the ...

  25. How to Delete Folders with PowerShell Remove-Item

    To delete folders with PowerShell we will need to use the Remove-Item cmdlet. This cmdlet can not only be used to delete folders, but also for removing files, registry keys, and more. We will focus on deleting folders in this article. The Remove-Item cmdlet comes with a couple of parameters that we can use to specify the folder that we want to ...

  26. Set-MsolUserLicense (MSOnline)

    Example 1: Add a license to a user PowerShell PS C:\> Set-MsolUserLicense -UserPrincipalName "[email protected]" -AddLicenses "Contoso:ENTERPRISEPACK" This command adds the Office 365 for Enterprises license to the user. Example 2: Remove a license from a user PowerShell

  27. Export Microsoft 365 users last sign-in date and time

    Expand Identity > Users > All users. Click Sign-in logs. Click the tab User sign-ins (interactive) A list of all the users' sign-ins with the date and time of the last 7 days appears by default. You can always change the date, but it can only show you the sign-ins for the last month.