I need a method to get all user accounts in Office365 (synced from on-prem AD with AADSync), that are NOT shared mailboxes. I also need to know if they have a license, but I already know that bit.

I need this to potentially assign them a license.

The flow:

  1. A new AD account is created on premises
  2. It is synced with AADSync to AAD/Office365
  3. A process queries AAD for users and uses custom logic to determine, if a user should get a license assigned or not. The newly created account is returned and listed as having no license
  4. Process assigns license to new account, because a business rule says so

How do I do step 3 here?

I currently use something like this:

Get-MsolUser -MaxResults Unlimited | Select-Object UserPrincipalName,IsLicensed,UsageLocation,Licenses

...But this also returns shared mailboxes, which I do not want.

  • I'm not entirely sure I understand what you are trying to do, the powershell command you have listed returns all users, so I'm guessing you have some more code. Try this to see if it gets you what you want. PS C:\> Get-MsolUser | Select-Object UserPrincipalName,IsLicensed,UsageLocation,Licenses | foreach {$_.UserPrincipalName} {Get-Mailbox -ErrorAction SilentlyContinue -identity $_.UserPrincipalName -Filter {(-not(RecipientTypeDetailsValue -eq 'SharedMailbox')) -and (-not(RecipientTypeDetailsValue -eq 'RoomMailbox')) -and (-not(RecipientTypeDetailsValue -eq 'EquipmentMailbox'))}} – Drifter104 Sep 9 '16 at 12:04

If you supply account details on step 1, you just need to query AAD for a specific UPN you've just created with Get-MsolUser -UserPrincipalName user@domain which will return the object, along with licensing status.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.