Home

Finding a list of users who don't have an exchange license

%3CLINGO-SUB%20id%3D%22lingo-sub-250980%22%20slang%3D%22en-US%22%3EFinding%20a%20list%20of%20users%20who%20don't%20have%20an%20exchange%20license%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-250980%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20the%20O365%20admin%20for%20my%20company%2C%20and%20my%20boss%20recently%20asked%20me%20to%20give%20him%20a%20list%20of%20all%20regular%20users%20in%20our%20AD%20trees%20who%20weren't%20licensed%20online%20for%20Exchange.%26nbsp%3B%20This%20has%20turned%20out%20to%20be%20more%20complicated%20than%20I%20thought%20it%20would%20be.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWe%20are%20in%20the%20process%20of%20migrating%20users%20from%20on-prem%20to%20the%20cloud%2C%20and%20we%20are%20trying%20to%20head%20off%20any%20problems%20with%20on-prem%20users%20who%20somehow%20didn't%20get%20a%20o365%20license.%26nbsp%3B%20Those%20cause%20real%20problems%20when%20a%20user's%20on%20prem%20email%20gets%20migrated%20to%20the%20cloud%20and%20it%20turns%20out%20he%2Fshe%20doesn't%20have%20a%20license%20beforehand.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThe%20exchange%20admin%20and%20I%20have%20been%20playing%20around%20with%20powershell%2C%20and%20this%20is%20the%20best%20command%20that%20we%20have%20been%20able%20to%20come%20up%20with.%3C%2FP%3E%3CP%3EGet-MsolUser%20-All%20%7C%20where%20%7B%26nbsp%3B%20%24_.isLicensed%20-eq%20%24true%7D%26nbsp%3B%7C%20export-csv%20-notype%20-path%20xxxx%20%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhile%20that%20technically%20works%2C%20it%20gives%20me%20a%20lot%20of%20stuff%20that%20I%20don't%20want.%26nbsp%3B%20It%20gives%20me%20all%20the%20contractors%2C%20who%20we%20aren't%20moving%20and%20are%20not%20buying%20licenses%20for%2C%20as%20well%20as%20disabled%20users%2C%20system%20accounts%2C%20and%20so%20on.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EOne%20good%20thing%20about%20this%20is%20that%20it%20has%20shown%20me%20that%20we%20are%20syncing%20more%20than%20I%20thought%20we%20were%2C%20(like%20the%20disabled%20and%20service%20accounts)%2C%20but%20now%20I%20have%20to%20figure%20out%20how%20to%20remove%20all%20that%20junk%20from%20the%20final%20report.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EUnfortunately%20there%20are%20a%20LOT%20of%20AD%20fields%20that%20don't%20come%20across%20to%20Azure%20AD.%26nbsp%3B%20I%20assume%20this%20means%20I'll%20have%20to%20run%20a%20couple%20different%20commands.%26nbsp%3B%20The%20first%20one%20against%20AAD%2C%20and%20then%20another%20against%20regular%20AD.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECan%20anyone%20point%20me%20towards%20a%20PS%20command%20that%20I%20could%20run%20against%20AD%20that%20I%20could%20use%20to%20take%20my%20current%20exported%20csv%20file%2C%20and%20try%20to%20find%20out%20if%20the%20user%20is%20in%20the%20OU%20that%20has%20the%20word%20%22contractors%22%20in%20it%3F%26nbsp%3B%20(Each%20of%20our%20locations%20has%20a%20users%2Fcontractors%20OU%20under%20it%20where%20all%20contractors%20are%20placed).%26nbsp%3B%20I%20have%20the%20UPN%20for%20every%20user%20which%20I%20assume%20could%20be%20tied%20back%20to%20AD.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWe%20also%20have%20a%20separate%20OU%20under%20each%20location%20OU%20for%20disabled%20users.%26nbsp%3B%20I%20assume%20I%20could%20filter%20out%20that%20as%20well%20somehow.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20list%20of%20users%20with%20no%20exchange%20license%20is%20several%20thousand%20long%2C%20and%20I'd%20REALLY%20prefer%20to%20not%20have%20to%20do%20this%20manually.%26nbsp%3B%20I'm%20kind%20of%20lazy%20that%20way.%26nbsp%3B%20%3A-)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20in%20advance%20for%20your%20help.%3C%2FP%3E%3CP%3ETed%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-250980%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExchange%20Online%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-255212%22%20slang%3D%22en-US%22%3ERe%3A%20Finding%20a%20list%20of%20users%20who%20don't%20have%20an%20exchange%20license%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-255212%22%20slang%3D%22en-US%22%3E%3CP%3EOne%20example%3A%3C%2FP%3E%0A%3CP%3EUsing%20on-prem%20Exch%20PS%3A%3C%2FP%3E%0A%3CP%3E%24list%20%3D%20Get-Mailbox%26nbsp%3B%20-resultsize%20unlimited%20%7C%20%3F%7B%24_.OrganizationalUnit%20-notmatch%20'Contractors'%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%24list.userprincipalname%20%26gt%3B%20list.txt%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThen%20using%20Ex%20Online%20PS%3A%3C%2FP%3E%0A%3CP%3E%24list%20%3D%26nbsp%3Bgc%20.%5Clist.txt%3C%2FP%3E%0A%3CP%3Eforeach%20(%24id%20in%20%24list)%20%7Bget-msoluser%20-UserPrincipalName%20%24id%20%7C%20%3F%7B%24_.IsLicensed%20-eq%20%24false%20%7D%7D%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThat%20will%20give%20you%20a%20list%20of%20users%20not%20licensed.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EManipulate%20or%20change%20search%20as%20you%20see%20fit.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-253208%22%20slang%3D%22en-US%22%3ERe%3A%20Finding%20a%20list%20of%20users%20who%20don't%20have%20an%20exchange%20license%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-253208%22%20slang%3D%22en-US%22%3EThis%20would%20probably%20be%20a%20good%20start%20for%20you%20to%20review%20in%20regards%20to%20the%20modules%20needed%20for%20Office%20365.%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice365%2Fenterprise%2Fpowershell%2Fgetting-started-with-office-365-powershell%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Foffice365%2Fenterprise%2Fpowershell%2Fgetting-started-with-office-365-powershell%3C%2FA%3E%3CBR%20%2F%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-251284%22%20slang%3D%22en-US%22%3ERe%3A%20Finding%20a%20list%20of%20users%20who%20don't%20have%20an%20exchange%20license%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-251284%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20for%20the%20reply.%26nbsp%3B%20I%20wasn't%20aware%20of%20the%20L%26amp%3BF%20feature%2C%20but%20we%20probably%20won't%20be%20able%20to%20use%20it.%26nbsp%3B%20My%20company%20has%20around%2050%20or%20so%20location%20specific%20OU's%2C%20and%20under%20each%20one%20is%20a%20Users%20OU%2C%20and%20then%20under%20that%20is%20a%20Disabled%20OU.%26nbsp%3B%20Any%20time%20a%20user%20leaves%20the%20company%20their%20account%20is%20disabled%20and%20then%20they%20are%20moved%20to%20that%20OU.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20thought%20we%20had%20set%20up%20AAD%20to%20not%20sync%20all%20of%20those%20Disabled%20OU's%2C%20(in%20fact%20I%20vaguely%20remember%20how%20much%20of%20a%20pain%20it%20was%20to%20configure%20all%20of%20those%20exceptions)%2C%20but%20for%20some%20reason%20that%20must%20have%20changed%20after%20it%20was%20set%20up.%26nbsp%3B%20We'll%20have%20to%20go%20back%20now%20and%20figure%20out%20what%20that%20is%20no%20longer%20happening.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-251281%22%20slang%3D%22en-US%22%3ERe%3A%20Finding%20a%20list%20of%20users%20who%20don't%20have%20an%20exchange%20license%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-251281%22%20slang%3D%22en-US%22%3E%3CP%3EThanks%20for%20your%20reply%20and%20link.%26nbsp%3B%20%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI'm%20not%20even%20remotely%20a%20powershell%20guru%2C%20so%20I'm%20not%20familiar%20with%20how%20adding%20extra%20modules%20in%20will%20affect%20things%20long%20term.%26nbsp%3B%20If%20I%20download%20and%20install%20that%20module%2C%20are%20there%20any%20risks%20to%20that%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EPart%20of%20my%20problem%20is%20that%20I%20got%20a%20new%20computer%20recently%2C%20and%20I'm%20having%20a%20heck%20of%20a%20time%20figuring%20out%20which%20modules%20I%20had%20loaded%20on%20my%20last%20computer.%26nbsp%3B%20Some%20of%20the%20commands%20I%20used%20to%20run%20no%20longer%20work%2C%20and%20I%20can't%20figure%20out%20what%20they%20were%20from.%26nbsp%3B%20I'm%20a%20little%20nervous%20now%20about%20loading%20any%20other%20modules%20that%20later%20I'm%20not%20going%20to%20remember%20I%20loaded.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20again%20for%20your%20help.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-251078%22%20slang%3D%22en-US%22%3ERe%3A%20Finding%20a%20list%20of%20users%20who%20don't%20have%20an%20exchange%20license%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-251078%22%20slang%3D%22en-US%22%3E%3CP%3EFor%20what's%20worth%2C%20putting%20users%20(special%20non%20users%20accounts)%20into%20LostAndFound%20in%20AD%20will%20make%20them%20not%20to%20sync%20to%20AAD.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-251049%22%20slang%3D%22en-US%22%3ERe%3A%20Finding%20a%20list%20of%20users%20who%20don't%20have%20an%20exchange%20license%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-251049%22%20slang%3D%22en-US%22%3E%3CP%3EMSOLLicenseManagementProvides%20in%20the%20PowerShell%20Gallery%20may%20be%20what%20your%20looking%20for.%20It%20functions%20to%20simplify%20the%20management%20of%20License%20Assignment%2C%20Swapping%2C%20Updating%2C%20and%20Reporting%20in%20Office%20365.%3CBR%20%2F%3E%3CA%20href%3D%22https%3A%2F%2Fwww.powershellgallery.com%2Fpackages%2FMSOLLicenseManagement%2F1.0.12%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.powershellgallery.com%2Fpackages%2FMSOLLicenseManagement%2F1.0.12%3C%2FA%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Ted McLaughlin
New Contributor

I am the O365 admin for my company, and my boss recently asked me to give him a list of all regular users in our AD trees who weren't licensed online for Exchange.  This has turned out to be more complicated than I thought it would be.

 

We are in the process of migrating users from on-prem to the cloud, and we are trying to head off any problems with on-prem users who somehow didn't get a o365 license.  Those cause real problems when a user's on prem email gets migrated to the cloud and it turns out he/she doesn't have a license beforehand.

 

The exchange admin and I have been playing around with powershell, and this is the best command that we have been able to come up with.

Get-MsolUser -All | where {  $_.isLicensed -eq $true} | export-csv -notype -path xxxx ;

 

While that technically works, it gives me a lot of stuff that I don't want.  It gives me all the contractors, who we aren't moving and are not buying licenses for, as well as disabled users, system accounts, and so on.  

 

One good thing about this is that it has shown me that we are syncing more than I thought we were, (like the disabled and service accounts), but now I have to figure out how to remove all that junk from the final report.  

 

Unfortunately there are a LOT of AD fields that don't come across to Azure AD.  I assume this means I'll have to run a couple different commands.  The first one against AAD, and then another against regular AD.

 

Can anyone point me towards a PS command that I could run against AD that I could use to take my current exported csv file, and try to find out if the user is in the OU that has the word "contractors" in it?  (Each of our locations has a users/contractors OU under it where all contractors are placed).  I have the UPN for every user which I assume could be tied back to AD.

 

We also have a separate OU under each location OU for disabled users.  I assume I could filter out that as well somehow.

 

My list of users with no exchange license is several thousand long, and I'd REALLY prefer to not have to do this manually.  I'm kind of lazy that way.  :-)

 

Thanks in advance for your help.

Ted

 

6 Replies

MSOLLicenseManagementProvides in the PowerShell Gallery may be what your looking for. It functions to simplify the management of License Assignment, Swapping, Updating, and Reporting in Office 365.
https://www.powershellgallery.com/packages/MSOLLicenseManagement/1.0.12

For what's worth, putting users (special non users accounts) into LostAndFound in AD will make them not to sync to AAD. 

Thanks for your reply and link.   

 

I'm not even remotely a powershell guru, so I'm not familiar with how adding extra modules in will affect things long term.  If I download and install that module, are there any risks to that?

 

Part of my problem is that I got a new computer recently, and I'm having a heck of a time figuring out which modules I had loaded on my last computer.  Some of the commands I used to run no longer work, and I can't figure out what they were from.  I'm a little nervous now about loading any other modules that later I'm not going to remember I loaded.

 

Thanks again for your help.

Thanks for the reply.  I wasn't aware of the L&F feature, but we probably won't be able to use it.  My company has around 50 or so location specific OU's, and under each one is a Users OU, and then under that is a Disabled OU.  Any time a user leaves the company their account is disabled and then they are moved to that OU.

 

I thought we had set up AAD to not sync all of those Disabled OU's, (in fact I vaguely remember how much of a pain it was to configure all of those exceptions), but for some reason that must have changed after it was set up.  We'll have to go back now and figure out what that is no longer happening.

This would probably be a good start for you to review in regards to the modules needed for Office 365. https://docs.microsoft.com/en-us/office365/enterprise/powershell/getting-started-with-office-365-pow...

One example:

Using on-prem Exch PS:

$list = Get-Mailbox  -resultsize unlimited | ?{$_.OrganizationalUnit -notmatch 'Contractors'}

 $list.userprincipalname > list.txt

 

Then using Ex Online PS:

$list = gc .\list.txt

foreach ($id in $list) {get-msoluser -UserPrincipalName $id | ?{$_.IsLicensed -eq $false }}

 

That will give you a list of users not licensed.

 

Manipulate or change search as you see fit.

 

 

Related Conversations
Replace when wild cards used
Bud Tripp in Excel on
2 Replies