Advertisement
Guest User

Untitled

a guest
Oct 11th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.52 KB | None | 0 0
  1. # Install the AzureAD Preview Module
  2. # Install-Module -Name AzureADPreview -MinimumVersion 2.0.0.7 -Force -SkipPublisherCheck
  3.  
  4. # Import the Module
  5. Import-Module AzureADPreview -RequiredVersion 2.0.0.7
  6.  
  7. # Tenant Name
  8. $tenantID = "tenant.customer.com"
  9. # Admin User for the Tenant
  10. $username = "admin@tenant.customer.com"
  11. # Password for the Admin User
  12. $password = 'MyP@ssw0rd!' | convertto-securestring -AsPlainText -Force
  13. # Credentials for the Admin User
  14. $credentials = New-Object System.Management.Automation.PSCredential $Username,$password
  15.  
  16. #Connect to your AzureAD tenant
  17. Connect-AzureAD -TenantId $tenantID -Credential $credentials
  18.  
  19. # Get the License SkuId from a similar user that we want to apply to the new user
  20. $licensedUser = Get-AzureADUser -ObjectId "templateuser@tenant.customer.com"
  21. $licensedUser.AssignedLicenses
  22.  
  23. # Get the New User we want to apply the license too
  24. $user = Get-AzureADUser -ObjectId "newuser@tenant.customer.com"
  25. # check to see they have no license
  26. $user.AssignedLicenses
  27.  
  28. # Create the new License Object
  29. $license = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
  30. $license.SkuId = $licensedUser.AssignedLicenses.SkuId
  31.  
  32. # Create the Licenses Table and add the license from above
  33. $licenses = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicenses
  34. $licenses.AddLicenses = $license
  35.  
  36. # Apply the license to the new user
  37. Set-AzureADUserLicense -ObjectId $user.ObjectId -AssignedLicenses $licenses
  38. # check to see license has applied
  39. $user = Get-AzureADUser -ObjectId $user.ObjectId
  40. $user.AssignedLicenses
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement