Home
%3CLINGO-SUB%20id%3D%22lingo-sub-961128%22%20slang%3D%22en-US%22%3EStep-by-Step%3A%20Managing%20Users%20via%20the%20Azure%20Active%20Directory%20PowerShell%20for%20Graph%20Module%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-961128%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EMicrosoft%20Graph%20provides%20a%20unified%20programmability%20model%20to%20access%20a%20vast%20amount%20of%20data%20in%20Microsoft%20365%2C%20Azure%20Active%20Directory%2C%20Enterprise%20Mobility%20Suite%2C%20Windows%2010%20and%20so%20on.%20As%20part%20of%20it%2C%20Azure%20AD%20PowerShell%20for%20Graph%20module%20allows%20us%20to%20retrieve%20data%2C%20update%20directory%20configuration%2C%20add%2Fupdate%2Fremove%20objects%20and%20configure%20features%20via%20Microsoft%20Graph.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EIn%20this%20post%2C%20I%20am%20going%20to%20demonstrate%20how%20we%20can%20manage%20Azure%20Active%20Directory%20users%20using%20%3CSTRONG%3EAzure%20Active%20Directory%20PowerShell%20for%20Graph%20module%3C%2FSTRONG%3E.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CU%3E%3CSTRONG%3EInstallation%3C%2FSTRONG%3E%3C%2FU%3E%3C%2FP%3E%0A%3CP%3EAzure%20Active%20Directory%20PowerShell%20for%20Graph%20module%20comes%20as%20two%20versions.%20The%20public%20preview%20version%20is%20the%20latest%20version%20but%20it%20is%20not%20recommended%20to%20use%20in%20production.%20The%20installation%20steps%20for%20this%20version%20can%20be%20found%20on%20%3CA%20href%3D%22https%3A%2F%2Fwww.powershellgallery.com%2Fpackages%2FAzureADPreview%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.powershellgallery.com%2Fpackages%2FAzureADPreview%3C%2FA%3E%20.%3C%2FP%3E%0A%3CP%3EGeneral%20Availability%20version%20is%20the%20stable%20and%20recommended%20version%20for%20production%20environments.%20This%20can%20be%20installed%20in%20any%20computer%20which%20runs%20Windows%20Server%202008%20R2%20or%20above%20with%20the%20latest%20updates.%20This%20is%20also%20required%20Microsoft%20.NET%20framework%204.5%20or%20above.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOnce%20prerequisites%20are%20in%20place%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3ELog%20in%20to%20the%20computer%20you%20have%20selected%20for%20Azure%20Active%20Directory%20PowerShell%20for%20Graph%20module%3C%2FLI%3E%0A%3CLI%3ELaunch%20PowerShell%20console%20as%20Administrator%3C%2FLI%3E%0A%3CLI%3ERun%20%3CSTRONG%3EInstall-Module%20-Name%20AzureAD%3C%2FSTRONG%3E%20command.%20Answer%20%22%3CSTRONG%3EYes%3C%2FSTRONG%3E%22%20if%20it%20is%20required%20repository%20update.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20855px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F151630i689CB191F26148D0%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%2216_1.png%22%20title%3D%2216_1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E4.%20After%20installation%2C%20we%20can%20verify%20module%20install%20using%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EGet-Module%20AzureAD%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E5.%20After%20the%20successful%20module%20installation%2C%20run%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EConnect-AzureAD%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20initiate%20the%20connection%20to%20Azure%20AD%20tenant.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E6.%20Then%20it%20will%20prompt%20a%20login%20window.%20Use%20Azure%20AD%20global%20administrator%20account%20details%20to%20connect.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20839px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F151632iC17C1ABD02A98BF9%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%2216_2.png%22%20title%3D%2216_2.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ENow%20we%20have%20Azure%20Active%20Directory%20PowerShell%20for%20Graph%20module%20installed.%20Let's%20see%20how%20we%20can%20manage%20Azure%20AD%20hybrid-environment%20using%20this%20module.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CU%3E%3CSTRONG%3EManage%20Users%3C%2FSTRONG%3E%3C%2FU%3E%3C%2FP%3E%0A%3CP%3ELet's%20see%20how%20we%20can%20Manage%20use%20accounts%20using%20Azure%20Active%20Directory%20PowerShell%20for%20Graph%20module.%3C%2FP%3E%0A%3CP%3EWe%20can%20view%20user%20accounts%20details%20for%20a%20known%20account%20using%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUser%20-ObjectId%20AdeleV%40M365x562652.OnMicrosoft.com%20%7C%20fl%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20the%20above%20command%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EAdeleV%40M365x562652.OnMicrosoft.com%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Erepresents%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EUPN%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eof%20the%20user.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20also%20can%20use%20user%20attributes%20to%20find%20user%20account%20details.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUser%20-Filter%20%22startswith(GivenName%2C'Adele')%22%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPreceding%20command%20will%20filter%20Azure%20AD%20users%20with%20Given%20Name%3A%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EAdele%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EWe%20also%20can%20filter%20users%20based%20on%20specific%20attribute%20value.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUser%20-Filter%20%22GivenName%20eq%20'Adele'%22%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAbove%20command%20will%20search%20for%20the%20exact%20user%20with%20given%20name-value%20Adele.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20my%20demo%20environment%2C%20I%20like%20to%20see%20list%20of%20disabled%20account.%20I%20can%20do%20it%20using%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUser%20-All%20%24true%20-Filter%20'accountEnabled%20eq%20false'%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20can%20modify%20the%20output%20of%20the%20filtered%20data%20further.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUser%20-All%20%24true%20-Filter%20'accountEnabled%20eq%20false'%20%7C%20select%20DisplayName%2CUserPrincipalName%2CDepartment%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPreceding%20command%20will%20display%20value%20of%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EDisplayName%2CUserPrincipalName%2CDepartment%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FSTRONG%3Eattributes%20of%20filtered%20accounts.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20hybrid%20environment%2C%20we%20can%20filter%20accounts%20which%20is%20synced%20from%20on-premises%20AD%20by%20using%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUser%20-All%20%24true%20-Filter%20'DirSyncEnabled%20eq%20true'%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20above%20command%2C%20value%20of%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EDirSyncEnabled%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FSTRONG%3Eattribute%20defines%20if%20it's%20a%20cloud%20only%20account%20or%20synced%20account.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20also%20can%20check%20the%20last%20sync%20value%20for%20the%20synced%20accounts.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUser%26nbsp%3B%20-All%20%24true%20-Filter%20'DirSyncEnabled%20eq%20true'%20%7C%20select%20DisplayName%2CUserPrincipalName%2CLastDirSyncTime%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20above%20command%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ELastDirSyncTime%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evalue%20defines%20last%20sync%20time%20of%20the%20object.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20also%20can%20export%20the%20output%20to%20a%20CSV%20file%20using%3CSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EExport-CSV%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FSTRONG%3Ecommand.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUser%26nbsp%3B%20-All%20%24true%20-Filter%20'DirSyncEnabled%20eq%20true'%20%7C%20select%20DisplayName%2CUserPrincipalName%2CLastDirSyncTime%20%7C%20Export-CSV%20-Path%20.%5Csyncaccount.csv%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EImmutableID%26nbsp%3B%3C%2FSTRONG%3Evalue%20of%20a%20user%20account%20is%20used%20to%20map%20Azure%20AD%20user%20object%20to%20on-premises%20user%20object.%20It%20does%20have%20a%20relationship%20with%20on-premises%20user%20accounts'%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EObjectGUID%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E.%20We%20can%20use%20this%20to%20identify%20cloud-only%20users.%20If%20it%20is%20a%20cloud-only%20user%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EImmutableID%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evalue%20should%20be%20null.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUser%20-All%20%24true%20%7C%20where-Object%20%7B%24_.ImmutableId%20-eq%20%24null%7D%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPreceding%20command%20return%20list%20of%20all%20the%20cloud%20only%20accounts.%20We%20can%20export%20the%20required%20attribute%20values%20to%20CSV%20by%20using%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUser%20-All%20%24true%20%7C%20where-Object%20%7B%24_.ImmutableId%20-eq%20%24null%7D%20%7C%20select%20DisplayName%2CUserPrincipalName%20%7C%20Export-CSV%20-Path%20.%5Ccloudaccount.csv%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAnother%20important%20thing%20related%20to%20account%20is%20%22licences%22.%20If%20we%20are%20going%20to%20use%20Azure%20AD%20premium%20features%2C%20we%20need%20to%20have%20relevant%20licences%20assigned.%20By%20default%2C%20the%20user%20only%20has%20Azure%20AD%20free%20version%20features.%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20view%20licenses%20associated%20with%20a%20user%20account%2C%20we%20can%20use%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUserLicenseDetail%20-ObjectId%20MeganB%40M365x562652.OnMicrosoft.com%20%7C%20fl%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAbove%20command%20will%20return%20the%20licenses%20associated%20with%20user%3CSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EMeganB%40M365x562652.OnMicrosoft.com%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EWe%20also%20can%20view%20the%20subscribed%20SKUs%20using%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADSubscribedSku%20%7C%20fl%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAbove%20command%20list%20down%20all%20the%20details%20about%20licenses%20which%20is%20associated%20with%20the%20tenant.%20But%20mostly%20we%20only%20need%20to%20know%20how%20many%20licenses%20been%20used%20and%20how%20many%20licenses%20available.%20We%20can%20do%20it%20using%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADSubscribedSku%20%7C%20select%20SkuPartNumber%2CConsumedUnits%20-ExpandProperty%20PrepaidUnits%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20851px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F151636i0DF71E798C6C7471%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%2216_4.png%22%20title%3D%2216_4.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EIn%20the%20preceding%20example%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ESkuPartNumber%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evalue%20represent%20the%20licence%20part%20number.%20Value%20of%20Enabled%20field%20represent%20the%20number%20of%20purchased%20licences.%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EConsumedUnits%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Erepresent%20the%20number%20of%20used%20licences.%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet's%20go%20ahead%20and%20see%20how%20we%20can%20assign%20a%20new%20licence%20to%20a%20user.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20my%20environment%2C%20I%20have%20a%20user%20who%20synced%20from%20on-premises%20Azure%20AD%20who%20doesn't%20have%20a%20licence%20assigned.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUserLicenseDetail%20-ObjectId%20ADJellison%40M365x562652.onmicrosoft.com%20%7C%20fl%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20851px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F151638i457801633D1D025A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%2216_5.png%22%20title%3D%2216_5.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20first%20step%2C%20lets%20create%20objects%20to%20use%20in%20licence%20assignment%20process.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicence%20%3D%20New-Object%20-TypeName%20Microsoft.Open.AzureAD.Model.AssignedLicense%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicenceadd%20%3D%20New-Object%20-TypeName%20Microsoft.Open.AzureAD.Model.AssignedLicenses%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThen%20we%20need%20to%20find%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ESkuId%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eof%20the%20licences.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20am%20going%20to%20assign%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EENTERPRISEPREMIUM%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Elicence%20to%20the%20user.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicence.SkuId%20%3D%20(Get-AzureADSubscribedSku%20%7C%20Where-Object%20-Property%20SkuPartNumber%20-Value%20%22ENTERPRISEPREMIUM%22%20-EQ).SkuId%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThen%20we%20need%20to%20assign%20the%20licences%20to%20the%20object%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicenceadd.AddLicenses%20%3D%20%24newlicence%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20we%20can%20go%20ahead%20and%20assign%20the%20licence%20to%20the%20user%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ESet-AzureADUserLicense%20-ObjectId%20%22ADJellison%40M365x562652.onmicrosoft.com%22%20-AssignedLicenses%20%24newlicenceadd%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPreceding%20command%20assign%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EENTERPRISEPREMIUM%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Elicences%20to%20user%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EADJellison%40M365x562652.onmicrosoft.com%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20821px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F151640iD9F6A3CB37901AEE%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%2216_6.png%22%20title%3D%2216_6.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EIt%20is%20must%20to%20set%20UsageLocation%20value%20for%20users%20who%20sync%20from%20on-premises%20AD%2C%20before%20assign%20licences.%20We%20can%20do%20it%20by%20using%2C%20Set-AzureADUser%20-ObjectId%20ADJellison%40M365x562652.onmicrosoft.com%20-UsageLocation%20%22US%22%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20can%20remove%20the%20assigned%20licences%20using%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24licenseB%20%3D%20New-Object%20-TypeName%20Microsoft.Open.AzureAD.Model.AssignedLicenses%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24licenseB.RemoveLicenses%20%3D%26nbsp%3B%20(Get-AzureADSubscribedSku%20%7C%20Where-Object%20%7B%24_.SkuPartNumber%20-eq%20'ENTERPRISEPREMIUM'%7D).SkuId%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ESet-AzureADUserLicense%20-ObjectId%20%22ADJellison%40M365x562652.onmicrosoft.com%22%20-AssignedLicenses%20%24licenseB%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EUsing%20above%20commands%2C%20I%20have%20created%20following%20script%20to%20do%20following%2C%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ESearch%20for%20users%20who%20synced%20from%20on-premises%20AD.%3C%2FLI%3E%0A%3CLI%3EFrom%20those%20users%2C%20select%20the%20users%20who%20doesn't%20have%20Azure%20AD%20licences%20assigned.%3C%2FLI%3E%0A%3CLI%3ESet%20UsageLocation%20value%20for%20selected%20users.%3C%2FLI%3E%0A%3CLI%3EAssign%20Azure%20AD%20licences%20to%20selected%20users.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSTRONG%3E%23%23%23%23%23%23%23Script%20to%20Assign%20Licences%20to%20Synced%20Users%20from%20On-Permises%20AD%23%23%23%23%23%23%23%23%23%23%23%23%23%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EImport-Module%20AzureAD%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EConnect-AzureAD%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%23%23%23Filter%20Synced%20Users%20who%20doesnt%20have%20licence%20assigned%23%23%23%23%23%23%23%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24ADusers%20%3D%20Get-AzureADUser%20-All%20%24true%20-Filter%20'DirSyncEnabled%20eq%20true'%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24notlicenced%20%3D%20Get-AzureADUser%20-All%20%24true%20%7C%20Where-Object%20%7B%24ADusers.AssignedLicenses%20-ne%20%24null%7D%20%7C%20select%20ObjectId%20%7C%20Out-File%20-FilePath%20C%3A%5Cusers.txt%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%23%23%23%23%23Set%20UsageLocation%20value%20to%20sync%20users%23%23%23%23%23%23%23%23%23%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E(Get-Content%20%22C%3A%5Cusers.txt%22%20%7C%20select-object%20-skip%203)%20%7C%20ForEach%20%7B%20Set-AzureADUser%20-ObjectId%20%24_%20-UsageLocation%20%22US%22%20%7D%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%23%23%23%23%23Set%20User%20Licecnes%23%23%23%23%23%23%23%23%23%23%23%23%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicence%20%3D%20New-Object%20-TypeName%20Microsoft.Open.AzureAD.Model.AssignedLicense%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicenceadd%20%3D%20New-Object%20-TypeName%20Microsoft.Open.AzureAD.Model.AssignedLicenses%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicence.SkuId%20%3D%20(Get-AzureADSubscribedSku%20%7C%20Where-Object%20-Property%20SkuPartNumber%20-Value%20%22ENTERPRISEPREMIUM%22%20-EQ).SkuId%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicenceadd.AddLicenses%20%3D%20%24newlicence%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E(Get-Content%20%22C%3A%5Cusers.txt%22%20%7C%20select-object%20-skip%203)%20%7C%20ForEach%20%7B%20Set-AzureADUserLicense%20-ObjectId%20%24_%20-AssignedLicenses%20%24newlicenceadd%20%7D%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20hybrid%20environment%2C%20users%20are%20mainly%20created%20through%20on-premises%20Active%20Directory%20but%20there%20are%20occasions%20where%20we%20need%20to%20add%20cloud%20only%20accounts.%20This%20is%20mainly%20for%20cloud%20management%20tasks.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20can%20create%20a%20new%20user%20by%20using%2C%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24Userpassword%20%3D%20New-Object%20-TypeName%20Microsoft.Open.AzureAD.Model.PasswordProfile%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24Userpassword.Password%20%3D%20%22London%401234%22%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ENew-AzureADUser%20-DisplayName%20%22Andrew%20Xavier%22%20-PasswordProfile%20%24Userpassword%20-UserPrincipalName%20%22Andrew.Xavier%40M365x562652.onmicrosoft.com%22%20-AccountEnabled%20%24true%20-MailNickName%20%22AndrewXavier%22%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20preceding%20command%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3E-PasswordProfile%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%20used%20to%20define%20the%20password%20profile%20for%20the%20new%20user%20account.%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3E-MailNickName%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Edefines%20value%20for%20user's%20mail%20nick%20name.%20Above%20example%2C%20add%20a%20new%20user%20account%20Andrew.Xavier%40M365x562652.onmicrosoft.com%20with%20password%20London%401234%3C%2FP%3E%0A%3CP%3EWe%20also%20can%20create%20multiple%20user%20accounts%20using%20CSV%20files.%20In%20below%20example%2C%20I%20am%20using%20a%20CSV%20file%20to%20create%20users.%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECSV%20file%20contains%20the%20following%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EUserPrincipalName%2C%20DisplayName%2CMailNickName%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EDishanM%40M365x562652.onmicrosoft.com%2C%20Dishan%20Melroy%2CDishanMel%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EJackM%40M365x562652.onmicrosoft.com%2CJack%20May%2CJackMay%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ERicahrdP%40M365x562652.onmicrosoft.com%2CRichard%20Parker%2CRichardPar%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThen%20I%20can%20create%20these%20new%20users%20using%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24Userpassword%20%3D%20New-Object%20-TypeName%20Microsoft.Open.AzureAD.Model.PasswordProfile%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24Userpassword.Password%20%3D%20%22London%401234%22%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EImport-Csv%20-Path%20C%3A%5Cnewuser.csv%20%7C%20foreach%20%7BNew-AzureADUser%20-UserPrincipalName%20%24_.UserPrincipalName%20-DisplayName%20%24_.DisplayName%20-MailNickName%20%24_.MailNickName%20-PasswordProfile%20%24Userpassword%20-AccountEnabled%20%24true%7D%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBy%20using%20above%20commands%2C%20I%20have%20created%20following%20script%20to%20do%2C%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ECreate%20new%20user%20accounts%20using%20CSV%20file%3C%2FLI%3E%0A%3CLI%3ESet%20UsageLocation%20for%20new%20user%20accounts%3C%2FLI%3E%0A%3CLI%3EAssign%20ENTERPRISEPREMIUM%20licences%20to%20users%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSTRONG%3E%23%23%23%23%23%23%23%23A%20Script%20to%20create%20new%20users%20and%20assign%20Azure%20AD%20licences%23%23%23%23%23%23%23%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EImport-Module%20AzureAD%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EConnect-AzureAD%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%23%23%23%23%23%23%23%23%23%23%23Create%20New%20Users%20using%20CSV%20%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24Userpassword%20%3D%20New-Object%20-TypeName%20Microsoft.Open.AzureAD.Model.PasswordProfile%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24Userpassword.Password%20%3D%20%22London%401234%22%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EImport-Csv%20-Path%20C%3A%5Cnewuser.csv%20%7C%20foreach%20%7BNew-AzureADUser%20-UserPrincipalName%20%24_.UserPrincipalName%20-DisplayName%20%24_.DisplayName%20-MailNickName%20%24_.MailNickName%20-PasswordProfile%20%24Userpassword%20-UsageLocation%20%22US%22%20-AccountEnabled%20%24true%7D%20%7C%20select%20ObjectId%20%7C%20Out-File%20-FilePath%20C%3A%5Cusers.txt%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%23%23%23%23%23%23%23%23%23%23%23Assign%20Licences%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicence%20%3D%20New-Object%20-TypeName%20Microsoft.Open.AzureAD.Model.AssignedLicense%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicenceadd%20%3D%20New-Object%20-TypeName%20Microsoft.Open.AzureAD.Model.AssignedLicenses%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicence.SkuId%20%3D%20(Get-AzureADSubscribedSku%20%7C%20Where-Object%20-Property%20SkuPartNumber%20-Value%20%22ENTERPRISEPREMIUM%22%20-EQ).SkuId%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicenceadd.AddLicenses%20%3D%20%24newlicence%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E(Get-Content%20%22C%3A%5Cusers.txt%22%20%7C%20select-object%20-skip%203)%20%7C%20ForEach%20%7B%20Set-AzureADUserLicense%20-ObjectId%20%24_%20-AssignedLicenses%20%24newlicenceadd%20%7D%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20remove%20Azure%20AD%20user%2C%20we%20can%20use%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ERemove-AzureADUser%20-ObjectId%20%22JDAllen%40M365x562652.onmicrosoft.com%22%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20can%20combine%20it%20with%20user%20search%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUser%20-Filter%20%22startswith(DisplayName%2C'Dishan')%22%20%7C%20Remove-AzureADUser%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAbove%20command%20will%20search%20for%20user%20accounts%20who%20has%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EDisplayName%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Estarts%20with%20%22Dishan%22.%20If%20there%20is%20any%2C%20second%20part%20of%20the%20command%20will%20remove%20it.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EThis%20marks%20the%20end%20of%20this%20post.%20I%20hope%20this%20was%20useful.%20The%20scripts%20used%20in%20the%20post%20is%20also%20available%20at%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Frebeladm%2Frebeladm%2Ftree%2Fmaster%2FAzureADGraphModule-Users%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Frebeladm%2Frebeladm%2Ftree%2Fmaster%2FAzureADGraphModule-Users%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-961128%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EMicrosoft%20Graph%20provides%20a%20unified%20programmability%20model%20to%20access%20a%20vast%20amount%20of%20data%20in%20Microsoft%20365%2C%20Azure%20Active%20Directory%2C%20Enterprise%20Mobility%20Suite%2C%20Windows%2010%20and%20so%20on.%20As%20part%20of%20it%2C%20Azure%20AD%20PowerShell%20for%20Graph%20module%20allows%20us%20to%20retrieve%20data%2C%20update%20directory%20configuration%2C%20add%2Fupdate%2Fremove%20objects%20and%20configure%20features%20via%20Microsoft%20Graph.%26nbsp%3B%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20740px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F151790i1DEDA143681901E4%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22Microsoft_Graph_Azure_Active_Directory.png%22%20title%3D%22Microsoft_Graph_Azure_Active_Directory.png%22%20%2F%3E%3CSPAN%20class%3D%22lia-inline-image-caption%22%20onclick%3D%22event.preventDefault()%3B%22%3EMicrosoft%20Graph%20Azure%20Active%20Directory%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EIn%20this%20post%2C%20I%20am%20going%20to%20demonstrate%20how%20we%20can%20manage%20Azure%20Active%20Directory%20users%20using%20%3CSTRONG%3EAzure%20Active%20Directory%20PowerShell%20for%20Graph%20module%3C%2FSTRONG%3E.%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CU%3E%3CSTRONG%3EInstallation%3C%2FSTRONG%3E%3C%2FU%3E%3C%2FP%3E%0A%3CP%3EAzure%20Active%20Directory%20PowerShell%20for%20Graph%20module%20comes%20as%20two%20versions.%20The%20public%20preview%20version%20is%20the%20latest%20version%20but%20it%20is%20not%20recommended%20to%20use%20in%20production.%20The%20installation%20steps%20for%20this%20version%20can%20be%20found%20on%20%3CA%20href%3D%22https%3A%2F%2Fwww.powershellgallery.com%2Fpackages%2FAzureADPreview%22%20target%3D%22_self%22%20rel%3D%22nofollow%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fwww.powershellgallery.com%2Fpackages%2FAzureADPreview%3C%2FA%3E%20.%3C%2FP%3E%0A%3CP%3EGeneral%20Availability%20version%20is%20the%20stable%20and%20recommended%20version%20for%20production%20environments.%20This%20can%20be%20installed%20in%20any%20computer%20which%20runs%20Windows%20Server%202008%20R2%20or%20above%20with%20the%20latest%20updates.%20This%20is%20also%20required%20Microsoft%20.NET%20framework%204.5%20or%20above.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOnce%20prerequisites%20are%20in%20place%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3ELog%20in%20to%20the%20computer%20you%20have%20selected%20for%20Azure%20Active%20Directory%20PowerShell%20for%20Graph%20module%3C%2FLI%3E%0A%3CLI%3ELaunch%20PowerShell%20console%20as%20Administrator%3C%2FLI%3E%0A%3CLI%3ERun%20%3CSTRONG%3EInstall-Module%20-Name%20AzureAD%3C%2FSTRONG%3E%20command.%20Answer%20%22%3CSTRONG%3EYes%3C%2FSTRONG%3E%22%20if%20it%20is%20required%20repository%20update.%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20855px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F151630i689CB191F26148D0%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%2216_1.png%22%20title%3D%2216_1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E4.%20After%20installation%2C%20we%20can%20verify%20module%20install%20using%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EGet-Module%20AzureAD%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E5.%20After%20the%20successful%20module%20installation%2C%20run%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EConnect-AzureAD%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eto%20initiate%20the%20connection%20to%20Azure%20AD%20tenant.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E6.%20Then%20it%20will%20prompt%20a%20login%20window.%20Use%20Azure%20AD%20global%20administrator%20account%20details%20to%20connect.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20839px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F151632iC17C1ABD02A98BF9%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%2216_2.png%22%20title%3D%2216_2.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3ENow%20we%20have%20Azure%20Active%20Directory%20PowerShell%20for%20Graph%20module%20installed.%20Let's%20see%20how%20we%20can%20manage%20Azure%20AD%20hybrid-environment%20using%20this%20module.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CU%3E%3CSTRONG%3EManage%20Users%3C%2FSTRONG%3E%3C%2FU%3E%3C%2FP%3E%0A%3CP%3ELet's%20see%20how%20we%20can%20Manage%20use%20accounts%20using%20Azure%20Active%20Directory%20PowerShell%20for%20Graph%20module.%3C%2FP%3E%0A%3CP%3EWe%20can%20view%20user%20accounts%20details%20for%20a%20known%20account%20using%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUser%20-ObjectId%20AdeleV%40M365x562652.OnMicrosoft.com%20%7C%20fl%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20the%20above%20command%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EAdeleV%40M365x562652.OnMicrosoft.com%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Erepresents%20the%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EUPN%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eof%20the%20user.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20also%20can%20use%20user%20attributes%20to%20find%20user%20account%20details.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUser%20-Filter%20%22startswith(GivenName%2C'Adele')%22%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPreceding%20command%20will%20filter%20Azure%20AD%20users%20with%20Given%20Name%3A%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EAdele%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EWe%20also%20can%20filter%20users%20based%20on%20specific%20attribute%20value.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUser%20-Filter%20%22GivenName%20eq%20'Adele'%22%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAbove%20command%20will%20search%20for%20the%20exact%20user%20with%20given%20name-value%20Adele.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20my%20demo%20environment%2C%20I%20like%20to%20see%20list%20of%20disabled%20account.%20I%20can%20do%20it%20using%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUser%20-All%20%24true%20-Filter%20'accountEnabled%20eq%20false'%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20can%20modify%20the%20output%20of%20the%20filtered%20data%20further.%26nbsp%3B%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUser%20-All%20%24true%20-Filter%20'accountEnabled%20eq%20false'%20%7C%20select%20DisplayName%2CUserPrincipalName%2CDepartment%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPreceding%20command%20will%20display%20value%20of%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EDisplayName%2CUserPrincipalName%2CDepartment%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FSTRONG%3Eattributes%20of%20filtered%20accounts.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20hybrid%20environment%2C%20we%20can%20filter%20accounts%20which%20is%20synced%20from%20on-premises%20AD%20by%20using%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUser%20-All%20%24true%20-Filter%20'DirSyncEnabled%20eq%20true'%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20above%20command%2C%20value%20of%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EDirSyncEnabled%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FSTRONG%3Eattribute%20defines%20if%20it's%20a%20cloud%20only%20account%20or%20synced%20account.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20also%20can%20check%20the%20last%20sync%20value%20for%20the%20synced%20accounts.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUser%26nbsp%3B%20-All%20%24true%20-Filter%20'DirSyncEnabled%20eq%20true'%20%7C%20select%20DisplayName%2CUserPrincipalName%2CLastDirSyncTime%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20above%20command%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ELastDirSyncTime%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evalue%20defines%20last%20sync%20time%20of%20the%20object.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20also%20can%20export%20the%20output%20to%20a%20CSV%20file%20using%3CSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EExport-CSV%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3C%2FSTRONG%3Ecommand.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUser%26nbsp%3B%20-All%20%24true%20-Filter%20'DirSyncEnabled%20eq%20true'%20%7C%20select%20DisplayName%2CUserPrincipalName%2CLastDirSyncTime%20%7C%20Export-CSV%20-Path%20.%5Csyncaccount.csv%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EImmutableID%26nbsp%3B%3C%2FSTRONG%3Evalue%20of%20a%20user%20account%20is%20used%20to%20map%20Azure%20AD%20user%20object%20to%20on-premises%20user%20object.%20It%20does%20have%20a%20relationship%20with%20on-premises%20user%20accounts'%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EObjectGUID%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E.%20We%20can%20use%20this%20to%20identify%20cloud-only%20users.%20If%20it%20is%20a%20cloud-only%20user%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EImmutableID%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evalue%20should%20be%20null.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUser%20-All%20%24true%20%7C%20where-Object%20%7B%24_.ImmutableId%20-eq%20%24null%7D%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPreceding%20command%20return%20list%20of%20all%20the%20cloud%20only%20accounts.%20We%20can%20export%20the%20required%20attribute%20values%20to%20CSV%20by%20using%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUser%20-All%20%24true%20%7C%20where-Object%20%7B%24_.ImmutableId%20-eq%20%24null%7D%20%7C%20select%20DisplayName%2CUserPrincipalName%20%7C%20Export-CSV%20-Path%20.%5Ccloudaccount.csv%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAnother%20important%20thing%20related%20to%20account%20is%20%22licences%22.%20If%20we%20are%20going%20to%20use%20Azure%20AD%20premium%20features%2C%20we%20need%20to%20have%20relevant%20licences%20assigned.%20By%20default%2C%20the%20user%20only%20has%20Azure%20AD%20free%20version%20features.%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20view%20licenses%20associated%20with%20a%20user%20account%2C%20we%20can%20use%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUserLicenseDetail%20-ObjectId%20MeganB%40M365x562652.OnMicrosoft.com%20%7C%20fl%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAbove%20command%20will%20return%20the%20licenses%20associated%20with%20user%3CSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3EMeganB%40M365x562652.OnMicrosoft.com%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EWe%20also%20can%20view%20the%20subscribed%20SKUs%20using%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADSubscribedSku%20%7C%20fl%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAbove%20command%20list%20down%20all%20the%20details%20about%20licenses%20which%20is%20associated%20with%20the%20tenant.%20But%20mostly%20we%20only%20need%20to%20know%20how%20many%20licenses%20been%20used%20and%20how%20many%20licenses%20available.%20We%20can%20do%20it%20using%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADSubscribedSku%20%7C%20select%20SkuPartNumber%2CConsumedUnits%20-ExpandProperty%20PrepaidUnits%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20851px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F151636i0DF71E798C6C7471%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%2216_4.png%22%20title%3D%2216_4.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EIn%20the%20preceding%20example%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ESkuPartNumber%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Evalue%20represent%20the%20licence%20part%20number.%20Value%20of%20Enabled%20field%20represent%20the%20number%20of%20purchased%20licences.%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EConsumedUnits%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Erepresent%20the%20number%20of%20used%20licences.%26nbsp%3B%3C%2FP%3E%0A%3CP%3ELet's%20go%20ahead%20and%20see%20how%20we%20can%20assign%20a%20new%20licence%20to%20a%20user.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20my%20environment%2C%20I%20have%20a%20user%20who%20synced%20from%20on-premises%20Azure%20AD%20who%20doesn't%20have%20a%20licence%20assigned.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUserLicenseDetail%20-ObjectId%20ADJellison%40M365x562652.onmicrosoft.com%20%7C%20fl%26nbsp%3B%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20851px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F151638i457801633D1D025A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%2216_5.png%22%20title%3D%2216_5.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20first%20step%2C%20lets%20create%20objects%20to%20use%20in%20licence%20assignment%20process.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicence%20%3D%20New-Object%20-TypeName%20Microsoft.Open.AzureAD.Model.AssignedLicense%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicenceadd%20%3D%20New-Object%20-TypeName%20Microsoft.Open.AzureAD.Model.AssignedLicenses%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThen%20we%20need%20to%20find%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3ESkuId%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eof%20the%20licences.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20am%20going%20to%20assign%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EENTERPRISEPREMIUM%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Elicence%20to%20the%20user.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicence.SkuId%20%3D%20(Get-AzureADSubscribedSku%20%7C%20Where-Object%20-Property%20SkuPartNumber%20-Value%20%22ENTERPRISEPREMIUM%22%20-EQ).SkuId%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThen%20we%20need%20to%20assign%20the%20licences%20to%20the%20object%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicenceadd.AddLicenses%20%3D%20%24newlicence%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20we%20can%20go%20ahead%20and%20assign%20the%20licence%20to%20the%20user%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ESet-AzureADUserLicense%20-ObjectId%20%22ADJellison%40M365x562652.onmicrosoft.com%22%20-AssignedLicenses%20%24newlicenceadd%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPreceding%20command%20assign%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EENTERPRISEPREMIUM%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Elicences%20to%20user%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EADJellison%40M365x562652.onmicrosoft.com%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20821px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F151640iD9F6A3CB37901AEE%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%2216_6.png%22%20title%3D%2216_6.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EIt%20is%20must%20to%20set%20UsageLocation%20value%20for%20users%20who%20sync%20from%20on-premises%20AD%2C%20before%20assign%20licences.%20We%20can%20do%20it%20by%20using%2C%20Set-AzureADUser%20-ObjectId%20ADJellison%40M365x562652.onmicrosoft.com%20-UsageLocation%20%22US%22%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20can%20remove%20the%20assigned%20licences%20using%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24licenseB%20%3D%20New-Object%20-TypeName%20Microsoft.Open.AzureAD.Model.AssignedLicenses%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24licenseB.RemoveLicenses%20%3D%26nbsp%3B%20(Get-AzureADSubscribedSku%20%7C%20Where-Object%20%7B%24_.SkuPartNumber%20-eq%20'ENTERPRISEPREMIUM'%7D).SkuId%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ESet-AzureADUserLicense%20-ObjectId%20%22ADJellison%40M365x562652.onmicrosoft.com%22%20-AssignedLicenses%20%24licenseB%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EUsing%20above%20commands%2C%20I%20have%20created%20following%20script%20to%20do%20following%2C%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ESearch%20for%20users%20who%20synced%20from%20on-premises%20AD.%3C%2FLI%3E%0A%3CLI%3EFrom%20those%20users%2C%20select%20the%20users%20who%20doesn't%20have%20Azure%20AD%20licences%20assigned.%3C%2FLI%3E%0A%3CLI%3ESet%20UsageLocation%20value%20for%20selected%20users.%3C%2FLI%3E%0A%3CLI%3EAssign%20Azure%20AD%20licences%20to%20selected%20users.%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSTRONG%3E%23%23%23%23%23%23%23Script%20to%20Assign%20Licences%20to%20Synced%20Users%20from%20On-Permises%20AD%23%23%23%23%23%23%23%23%23%23%23%23%23%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EImport-Module%20AzureAD%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EConnect-AzureAD%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%23%23%23Filter%20Synced%20Users%20who%20doesnt%20have%20licence%20assigned%23%23%23%23%23%23%23%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24ADusers%20%3D%20Get-AzureADUser%20-All%20%24true%20-Filter%20'DirSyncEnabled%20eq%20true'%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24notlicenced%20%3D%20Get-AzureADUser%20-All%20%24true%20%7C%20Where-Object%20%7B%24ADusers.AssignedLicenses%20-ne%20%24null%7D%20%7C%20select%20ObjectId%20%7C%20Out-File%20-FilePath%20C%3A%5Cusers.txt%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%23%23%23%23%23Set%20UsageLocation%20value%20to%20sync%20users%23%23%23%23%23%23%23%23%23%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E(Get-Content%20%22C%3A%5Cusers.txt%22%20%7C%20select-object%20-skip%203)%20%7C%20ForEach%20%7B%20Set-AzureADUser%20-ObjectId%20%24_%20-UsageLocation%20%22US%22%20%7D%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%23%23%23%23%23Set%20User%20Licecnes%23%23%23%23%23%23%23%23%23%23%23%23%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicence%20%3D%20New-Object%20-TypeName%20Microsoft.Open.AzureAD.Model.AssignedLicense%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicenceadd%20%3D%20New-Object%20-TypeName%20Microsoft.Open.AzureAD.Model.AssignedLicenses%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicence.SkuId%20%3D%20(Get-AzureADSubscribedSku%20%7C%20Where-Object%20-Property%20SkuPartNumber%20-Value%20%22ENTERPRISEPREMIUM%22%20-EQ).SkuId%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicenceadd.AddLicenses%20%3D%20%24newlicence%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E(Get-Content%20%22C%3A%5Cusers.txt%22%20%7C%20select-object%20-skip%203)%20%7C%20ForEach%20%7B%20Set-AzureADUserLicense%20-ObjectId%20%24_%20-AssignedLicenses%20%24newlicenceadd%20%7D%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20hybrid%20environment%2C%20users%20are%20mainly%20created%20through%20on-premises%20Active%20Directory%20but%20there%20are%20occasions%20where%20we%20need%20to%20add%20cloud%20only%20accounts.%20This%20is%20mainly%20for%20cloud%20management%20tasks.%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20can%20create%20a%20new%20user%20by%20using%2C%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24Userpassword%20%3D%20New-Object%20-TypeName%20Microsoft.Open.AzureAD.Model.PasswordProfile%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24Userpassword.Password%20%3D%20%22London%401234%22%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ENew-AzureADUser%20-DisplayName%20%22Andrew%20Xavier%22%20-PasswordProfile%20%24Userpassword%20-UserPrincipalName%20%22Andrew.Xavier%40M365x562652.onmicrosoft.com%22%20-AccountEnabled%20%24true%20-MailNickName%20%22AndrewXavier%22%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20preceding%20command%2C%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3E-PasswordProfile%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Eis%20used%20to%20define%20the%20password%20profile%20for%20the%20new%20user%20account.%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3E-MailNickName%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Edefines%20value%20for%20user's%20mail%20nick%20name.%20Above%20example%2C%20add%20a%20new%20user%20account%20Andrew.Xavier%40M365x562652.onmicrosoft.com%20with%20password%20London%401234%3C%2FP%3E%0A%3CP%3EWe%20also%20can%20create%20multiple%20user%20accounts%20using%20CSV%20files.%20In%20below%20example%2C%20I%20am%20using%20a%20CSV%20file%20to%20create%20users.%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECSV%20file%20contains%20the%20following%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EUserPrincipalName%2C%20DisplayName%2CMailNickName%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EDishanM%40M365x562652.onmicrosoft.com%2C%20Dishan%20Melroy%2CDishanMel%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EJackM%40M365x562652.onmicrosoft.com%2CJack%20May%2CJackMay%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ERicahrdP%40M365x562652.onmicrosoft.com%2CRichard%20Parker%2CRichardPar%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThen%20I%20can%20create%20these%20new%20users%20using%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24Userpassword%20%3D%20New-Object%20-TypeName%20Microsoft.Open.AzureAD.Model.PasswordProfile%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24Userpassword.Password%20%3D%20%22London%401234%22%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EImport-Csv%20-Path%20C%3A%5Cnewuser.csv%20%7C%20foreach%20%7BNew-AzureADUser%20-UserPrincipalName%20%24_.UserPrincipalName%20-DisplayName%20%24_.DisplayName%20-MailNickName%20%24_.MailNickName%20-PasswordProfile%20%24Userpassword%20-AccountEnabled%20%24true%7D%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EBy%20using%20above%20commands%2C%20I%20have%20created%20following%20script%20to%20do%2C%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3ECreate%20new%20user%20accounts%20using%20CSV%20file%3C%2FLI%3E%0A%3CLI%3ESet%20UsageLocation%20for%20new%20user%20accounts%3C%2FLI%3E%0A%3CLI%3EAssign%20ENTERPRISEPREMIUM%20licences%20to%20users%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E%3CSTRONG%3E%23%23%23%23%23%23%23%23A%20Script%20to%20create%20new%20users%20and%20assign%20Azure%20AD%20licences%23%23%23%23%23%23%23%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EImport-Module%20AzureAD%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EConnect-AzureAD%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%23%23%23%23%23%23%23%23%23%23%23Create%20New%20Users%20using%20CSV%20%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24Userpassword%20%3D%20New-Object%20-TypeName%20Microsoft.Open.AzureAD.Model.PasswordProfile%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24Userpassword.Password%20%3D%20%22London%401234%22%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EImport-Csv%20-Path%20C%3A%5Cnewuser.csv%20%7C%20foreach%20%7BNew-AzureADUser%20-UserPrincipalName%20%24_.UserPrincipalName%20-DisplayName%20%24_.DisplayName%20-MailNickName%20%24_.MailNickName%20-PasswordProfile%20%24Userpassword%20-UsageLocation%20%22US%22%20-AccountEnabled%20%24true%7D%20%7C%20select%20ObjectId%20%7C%20Out-File%20-FilePath%20C%3A%5Cusers.txt%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%23%23%23%23%23%23%23%23%23%23%23Assign%20Licences%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%23%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicence%20%3D%20New-Object%20-TypeName%20Microsoft.Open.AzureAD.Model.AssignedLicense%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicenceadd%20%3D%20New-Object%20-TypeName%20Microsoft.Open.AzureAD.Model.AssignedLicenses%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicence.SkuId%20%3D%20(Get-AzureADSubscribedSku%20%7C%20Where-Object%20-Property%20SkuPartNumber%20-Value%20%22ENTERPRISEPREMIUM%22%20-EQ).SkuId%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E%24newlicenceadd.AddLicenses%20%3D%20%24newlicence%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3E(Get-Content%20%22C%3A%5Cusers.txt%22%20%7C%20select-object%20-skip%203)%20%7C%20ForEach%20%7B%20Set-AzureADUserLicense%20-ObjectId%20%24_%20-AssignedLicenses%20%24newlicenceadd%20%7D%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20remove%20Azure%20AD%20user%2C%20we%20can%20use%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3ERemove-AzureADUser%20-ObjectId%20%22JDAllen%40M365x562652.onmicrosoft.com%22%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20can%20combine%20it%20with%20user%20search%2C%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EGet-AzureADUser%20-Filter%20%22startswith(DisplayName%2C'Dishan')%22%20%7C%20Remove-AzureADUser%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAbove%20command%20will%20search%20for%20user%20accounts%20who%20has%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3E%3CSTRONG%3EDisplayName%3C%2FSTRONG%3E%3CSPAN%3E%26nbsp%3B%3C%2FSPAN%3Estarts%20with%20%22Dishan%22.%20If%20there%20is%20any%2C%20second%20part%20of%20the%20command%20will%20remove%20it.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EThis%20marks%20the%20end%20of%20this%20post.%20I%20hope%20this%20was%20useful.%20The%20scripts%20used%20in%20the%20post%20is%20also%20available%20at%26nbsp%3B%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2Frebeladm%2Frebeladm%2Ftree%2Fmaster%2FAzureADGraphModule-Users%22%20target%3D%22_self%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2Frebeladm%2Frebeladm%2Ftree%2Fmaster%2FAzureADGraphModule-Users%3C%2FA%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-961128%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDishan%20Francis%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-985375%22%20slang%3D%22en-US%22%3ERe%3A%20Step-by-Step%3A%20Managing%20Users%20via%20the%20Azure%20Active%20Directory%20PowerShell%20for%20Graph%20Module%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-985375%22%20slang%3D%22en-US%22%3E%3CP%3EConnect-AzureAD%20should%20have%20a%20parameter%20%3CEM%3E-UserPrincipalName%3C%2FEM%3E%2C%20just%20like%20the%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2FExchange-Team-Blog%2FExchange-Admin-Improvements-Announced-at-Microsoft-Ignite-2019%2Fbc-p%2F985356%23M27381%22%20target%3D%22_self%22%3Enewly%20announced%20EXO%20PowerShell%20module%3C%2FA%3E.%20I%20don't%20want%20to%20have%20to%20enter%20my%20email%20address%20all%20the%20time%2C%20when%20I%20can%20just%20create%20an%20alias%20containing%20it.%20And%20why%20do%20I%20not%20have%20the%20option%20%22Do%20not%20ask%20me%20again%20for%2014%20days%22%20in%20the%20MFA%20window%20like%20we%20configured%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAny%20why%20does%20Get-AzureADUser%20not%20have%20an%20-Identity%20parameter%3F%20Instead%20it's%20named%20-ObjectId.%20Why%3F%20This%20should%20be%20standardized!%20Just%20compare%20with%20Get-EXOMailbox%2C%20Get-Mailbox%2C%20Get-ADUser%2C%20and%20so%20on.%20Stop%20working%20against%20expectations.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ELicense%20management%20is%20still%20as%20crappy%20as%20it%20always%20was.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3EGet-AzureADUser%20-ObjectId%20%26lt%3BUserPrincipalName%26gt%3B%20%7C%20Get-AzureADUserLicenseDetail%3C%2FPRE%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20761px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F155065iA53641CC2003F59A%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22grafik.png%22%20title%3D%22grafik.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3EWhat%20is%20this%3F%20There%20is%20literally%20ZERO%20information%20for%20me%20here.%20I%20have%20to%20jump%20through%20hoops%20if%20I%20want%20to%20see%20what's%20going%20on.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAnd%20when%20I%20do%2C%20I%20get%20%3CEM%3ESkuPartNumbers%3C%2FEM%3E%20that%20make%20%3CU%3Eabsolutely%20no%20sense%3C%2FU%3E.%20I%20expect%20to%20see%20the%20license%20and%20app%20name%20that%20I%20see%20in%20the%20admin%20center.%20Not%20some%20cryptic%20id%20that%20I%20have%20to%20memorize%20for%20no%20other%20reason%20that%20to%20use%20this%20horrible%20PowerShell%20module.%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20682px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F155071i3483F303E6552064%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20alt%3D%22grafik.png%22%20title%3D%22grafik.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20mean%2C%20just%20look%20at%20this%20article!%20Half%20of%20it%20explains%20how%20you%20assign%20licenses%20to%20a%20user.%20Something%20that%20should%20be%20possible%20with%20three%20PowerShell%20cmdlets.%20Why%20can't%20it%20be%20as%20simple%20as%20this%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3EGet-AzureADUser%20-Identity%20Jon.Doe%40contoso.com%20%7C%20Add-AzureADLicense%20-Name%20%22Office%20365%20E5%22%0AGet-AzureADUser%20-Identity%20Jon.Doe%40contoso.com%20%7C%20Set-AzureAdLicense%20-Name%20%22Office%20365%20E5%22%20-App%20%22Microsoft%20Kaizala%20Pro%22%20-Enabled%20%24false%3CBR%20%2F%3EGet-AzureADUser%20-Identity%20Jon.Doe%40contoso.com%20%7C%20Set-AzureAdLicense%20-Name%20%22Office%20365%20E5%22%20-App%20%22Microsoft%20Kaizala%20Pro%22%20-Enabled%20%24true%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Senior Member

Microsoft Graph provides a unified programmability model to access a vast amount of data in Microsoft 365, Azure Active Directory, Enterprise Mobility Suite, Windows 10 and so on. As part of it, Azure AD PowerShell for Graph module allows us to retrieve data, update directory configuration, add/update/remove objects and configure features via Microsoft Graph. 

 

In this post, I am going to demonstrate how we can manage Azure Active Directory users using Azure Active Directory PowerShell for Graph module.

 

Installation

Azure Active Directory PowerShell for Graph module comes as two versions. The public preview version is the latest version but it is not recommended to use in production. The installation steps for this version can be found on https://www.powershellgallery.com/packages/AzureADPreview .

General Availability version is the stable and recommended version for production environments. This can be installed in any computer which runs Windows Server 2008 R2 or above with the latest updates. This is also required Microsoft .NET framework 4.5 or above.

 

Once prerequisites are in place,

 

  1. Log in to the computer you have selected for Azure Active Directory PowerShell for Graph module
  2. Launch PowerShell console as Administrator
  3. Run Install-Module -Name AzureAD command. Answer "Yes" if it is required repository update.

16_1.png

4. After installation, we can verify module install using Get-Module AzureAD

5. After the successful module installation, run Connect-AzureAD to initiate the connection to Azure AD tenant. 

6. Then it will prompt a login window. Use Azure AD global administrator account details to connect. 

16_2.png

Now we have Azure Active Directory PowerShell for Graph module installed. Let's see how we can manage Azure AD hybrid-environment using this module. 

Manage Users

Let's see how we can Manage use accounts using Azure Active Directory PowerShell for Graph module.

We can view user accounts details for a known account using,

 

Get-AzureADUser -ObjectId AdeleV@M365x562652.OnMicrosoft.com | fl

 

In the above command, AdeleV@M365x562652.OnMicrosoft.com represents the UPN of the user. 

We also can use user attributes to find user account details. 

 

Get-AzureADUser -Filter "startswith(GivenName,'Adele')"

 

Preceding command will filter Azure AD users with Given Name: Adele

We also can filter users based on specific attribute value. 

 

Get-AzureADUser -Filter "GivenName eq 'Adele'"

 

Above command will search for the exact user with given name-value Adele. 

In my demo environment, I like to see list of disabled account. I can do it using,

 

Get-AzureADUser -All $true -Filter 'accountEnabled eq false'

 

We can modify the output of the filtered data further.  

 

Get-AzureADUser -All $true -Filter 'accountEnabled eq false' | select DisplayName,UserPrincipalName,Department

 

Preceding command will display value of DisplayName,UserPrincipalName,Department attributes of filtered accounts. 

In hybrid environment, we can filter accounts which is synced from on-premises AD by using,

 

Get-AzureADUser -All $true -Filter 'DirSyncEnabled eq true'

 

In above command, value of DirSyncEnabled attribute defines if it's a cloud only account or synced account. 

We also can check the last sync value for the synced accounts. 

 

Get-AzureADUser  -All $true -Filter 'DirSyncEnabled eq true' | select DisplayName,UserPrincipalName,LastDirSyncTime

 

In above command, LastDirSyncTime value defines last sync time of the object. 

We also can export the output to a CSV file using Export-CSV command.

 

Get-AzureADUser  -All $true -Filter 'DirSyncEnabled eq true' | select DisplayName,UserPrincipalName,LastDirSyncTime | Export-CSV -Path .\syncaccount.csv

 

ImmutableID value of a user account is used to map Azure AD user object to on-premises user object. It does have a relationship with on-premises user accounts' ObjectGUID . We can use this to identify cloud-only users. If it is a cloud-only user ImmutableID value should be null. 

 

Get-AzureADUser -All $true | where-Object {$_.ImmutableId -eq $null}

 

Preceding command return list of all the cloud only accounts. We can export the required attribute values to CSV by using,

 

Get-AzureADUser -All $true | where-Object {$_.ImmutableId -eq $null} | select DisplayName,UserPrincipalName | Export-CSV -Path .\cloudaccount.csv

 

Another important thing related to account is "licences". If we are going to use Azure AD premium features, we need to have relevant licences assigned. By default, the user only has Azure AD free version features. 

To view licenses associated with a user account, we can use,

 

Get-AzureADUserLicenseDetail -ObjectId MeganB@M365x562652.OnMicrosoft.com | fl

 

Above command will return the licenses associated with user MeganB@M365x562652.OnMicrosoft.com

We also can view the subscribed SKUs using,

 

Get-AzureADSubscribedSku | fl

 

Above command list down all the details about licenses which is associated with the tenant. But mostly we only need to know how many licenses been used and how many licenses available. We can do it using,

 

Get-AzureADSubscribedSku | select SkuPartNumber,ConsumedUnits -ExpandProperty PrepaidUnits

 

16_4.png

In the preceding example, SkuPartNumber value represent the licence part number. Value of Enabled field represent the number of purchased licences. ConsumedUnits represent the number of used licences. 

Let's go ahead and see how we can assign a new licence to a user. 

In my environment, I have a user who synced from on-premises Azure AD who doesn't have a licence assigned. 

 

Get-AzureADUserLicenseDetail -ObjectId ADJellison@M365x562652.onmicrosoft.com | fl 

 

16_5.png

 

As first step, lets create objects to use in licence assignment process. 

 

$newlicence = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense

$newlicenceadd = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses

 

Then we need to find SkuId of the licences. 

I am going to assign ENTERPRISEPREMIUM licence to the user.

 

$newlicence.SkuId = (Get-AzureADSubscribedSku | Where-Object -Property SkuPartNumber -Value "ENTERPRISEPREMIUM" -EQ).SkuId

 

Then we need to assign the licences to the object,

 

$newlicenceadd.AddLicenses = $newlicence

 

Now we can go ahead and assign the licence to the user,

 

Set-AzureADUserLicense -ObjectId "ADJellison@M365x562652.onmicrosoft.com" -AssignedLicenses $newlicenceadd

 

Preceding command assign ENTERPRISEPREMIUM licences to user ADJellison@M365x562652.onmicrosoft.com

 

16_6.png

It is must to set UsageLocation value for users who sync from on-premises AD, before assign licences. We can do it by using, Set-AzureADUser -ObjectId ADJellison@M365x562652.onmicrosoft.com -UsageLocation "US"

 

We can remove the assigned licences using,

 

$licenseB = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses

$licenseB.RemoveLicenses =  (Get-AzureADSubscribedSku | Where-Object {$_.SkuPartNumber -eq 'ENTERPRISEPREMIUM'}).SkuId

Set-AzureADUserLicense -ObjectId "ADJellison@M365x562652.onmicrosoft.com" -AssignedLicenses $licenseB

 

Using above commands, I have created following script to do following,

  • Search for users who synced from on-premises AD.
  • From those users, select the users who doesn't have Azure AD licences assigned.
  • Set UsageLocation value for selected users.
  • Assign Azure AD licences to selected users.

#######Script to Assign Licences to Synced Users from On-Permises AD#############

Import-Module AzureAD

Connect-AzureAD

###Filter Synced Users who doesnt have licence assigned#######

$ADusers = Get-AzureADUser -All $true -Filter 'DirSyncEnabled eq true'

$notlicenced = Get-AzureADUser -All $true | Where-Object {$ADusers.AssignedLicenses -ne $null} | select ObjectId | Out-File -FilePath C:\users.txt

#####Set UsageLocation value to sync users#########

(Get-Content "C:\users.txt" | select-object -skip 3) | ForEach { Set-AzureADUser -ObjectId $_ -UsageLocation "US" }

#####Set User Licecnes############

$newlicence = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense

$newlicenceadd = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses

$newlicence.SkuId = (Get-AzureADSubscribedSku | Where-Object -Property SkuPartNumber -Value "ENTERPRISEPREMIUM" -EQ).SkuId

$newlicenceadd.AddLicenses = $newlicence

(Get-Content "C:\users.txt" | select-object -skip 3) | ForEach { Set-AzureADUserLicense -ObjectId $_ -AssignedLicenses $newlicenceadd }

 

In hybrid environment, users are mainly created through on-premises Active Directory but there are occasions where we need to add cloud only accounts. This is mainly for cloud management tasks. 

We can create a new user by using, 

 

$Userpassword = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile

$Userpassword.Password = "London@1234"

New-AzureADUser -DisplayName "Andrew Xavier" -PasswordProfile $Userpassword -UserPrincipalName "Andrew.Xavier@M365x562652.onmicrosoft.com" -AccountEnabled $true -MailNickName "AndrewXavier"

 

In preceding command, -PasswordProfile is used to define the password profile for the new user account. -MailNickName defines value for user's mail nick name. Above example, add a new user account Andrew.Xavier@M365x562652.onmicrosoft.com with password London@1234

We also can create multiple user accounts using CSV files. In below example, I am using a CSV file to create users. 

CSV file contains the following,

 

UserPrincipalName, DisplayName,MailNickName

DishanM@M365x562652.onmicrosoft.com, Dishan Melroy,DishanMel

JackM@M365x562652.onmicrosoft.com,Jack May,JackMay

RicahrdP@M365x562652.onmicrosoft.com,Richard Parker,RichardPar

 

Then I can create these new users using,

 

$Userpassword = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile

$Userpassword.Password = "London@1234"

Import-Csv -Path C:\newuser.csv | foreach {New-AzureADUser -UserPrincipalName $_.UserPrincipalName -DisplayName $_.DisplayName -MailNickName $_.MailNickName -PasswordProfile $Userpassword -AccountEnabled $true}

 

By using above commands, I have created following script to do,

  • Create new user accounts using CSV file
  • Set UsageLocation for new user accounts
  • Assign ENTERPRISEPREMIUM licences to users

########A Script to create new users and assign Azure AD licences#######

Import-Module AzureAD

Connect-AzureAD

###########Create New Users using CSV ###################

$Userpassword = New-Object -TypeName Microsoft.Open.AzureAD.Model.PasswordProfile

$Userpassword.Password = "London@1234"

Import-Csv -Path C:\newuser.csv | foreach {New-AzureADUser -UserPrincipalName $_.UserPrincipalName -DisplayName $_.DisplayName -MailNickName $_.MailNickName -PasswordProfile $Userpassword -UsageLocation "US" -AccountEnabled $true} | select ObjectId | Out-File -FilePath C:\users.txt

###########Assign Licences#################

$newlicence = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense

$newlicenceadd = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses

$newlicence.SkuId = (Get-AzureADSubscribedSku | Where-Object -Property SkuPartNumber -Value "ENTERPRISEPREMIUM" -EQ).SkuId

$newlicenceadd.AddLicenses = $newlicence

(Get-Content "C:\users.txt" | select-object -skip 3) | ForEach { Set-AzureADUserLicense -ObjectId $_ -AssignedLicenses $newlicenceadd }

 

To remove Azure AD user, we can use

 

Remove-AzureADUser -ObjectId "JDAllen@M365x562652.onmicrosoft.com"

 

We can combine it with user search,

 

Get-AzureADUser -Filter "startswith(DisplayName,'Dishan')" | Remove-AzureADUser

 

Above command will search for user accounts who has DisplayName starts with "Dishan". If there is any, second part of the command will remove it.

 

This marks the end of this post. I hope this was useful. The scripts used in the post is also available at https://github.com/rebeladm/rebeladm/tree/master/AzureADGraphModule-Users

 

1 Comment
Frequent Contributor

Connect-AzureAD should have a parameter -UserPrincipalName, just like the newly announced EXO PowerShell module. I don't want to have to enter my email address all the time, when I can just create an alias containing it. And why do I not have the option "Do not ask me again for 14 days" in the MFA window like we configured?

 

Any why does Get-AzureADUser not have an -Identity parameter? Instead it's named -ObjectId. Why? This should be standardized! Just compare with Get-EXOMailbox, Get-Mailbox, Get-ADUser, and so on. Stop working against expectations.

 

License management is still as crappy as it always was.

 

Get-AzureADUser -ObjectId <UserPrincipalName> | Get-AzureADUserLicenseDetail

grafik.png

What is this? There is literally ZERO information for me here. I have to jump through hoops if I want to see what's going on.

 

And when I do, I get SkuPartNumbers that make absolutely no sense. I expect to see the license and app name that I see in the admin center. Not some cryptic id that I have to memorize for no other reason that to use this horrible PowerShell module.

grafik.png

 

 

I mean, just look at this article! Half of it explains how you assign licenses to a user. Something that should be possible with three PowerShell cmdlets. Why can't it be as simple as this?

 

Get-AzureADUser -Identity Jon.Doe@contoso.com | Add-AzureADLicense -Name "Office 365 E5"
Get-AzureADUser -Identity Jon.Doe@contoso.com | Set-AzureAdLicense -Name "Office 365 E5" -App "Microsoft Kaizala Pro" -Enabled $false
Get-AzureADUser -Identity Jon.Doe@contoso.com | Set-AzureAdLicense -Name "Office 365 E5" -App "Microsoft Kaizala Pro" -Enabled $true