├── Assign_AADPREMIUM_LicenseToAllUsers.ps1 ├── Assign_AADPREMIUM_LicenseToFilteredUsers.ps1 ├── Assign_AADPREMIUM_LicenseToUsersFromCSV.ps1 ├── ProvisionUsersAndAssignLicenseFromUserListCsv.ps1 ├── README.md ├── RELEASES.md └── UserList.csv /Assign_AADPREMIUM_LicenseToAllUsers.ps1: -------------------------------------------------------------------------------- 1 | # this script assigns the AAD_PREMIUM license to All Enabled users who do not currently have the AAD_PREMIUM license. 2 | 3 | # Authenticate the Administrator 4 | $cred = get-credential 5 | connect-msolservice -credential $cred 6 | 7 | 8 | # get the country's registered countryCode, use as users' default usageLocation if this propery is not set on users 9 | # usage location is required for each user to be licensed 10 | $tenant = Get-MsolCompanyInformation 11 | $defaultCompanyCountryCode = $tenant.CountryLetterCode 12 | 13 | #get the tenant's AAD Premium SKU 14 | $sku=Get-MsolAccountSku | where{$_.SkuPartNumber -ilike "AAD_PREMIUM"} 15 | 16 | # check the available unit count - if zero, then exit the script 17 | $availableUnits = $sku.ActiveUnits - $sku.ConsumedUnits 18 | if ($availableUnits -eq 0) 19 | { 20 | "You have No avaialable AAD_PREMIUM licenses" 21 | exit 22 | } 23 | 24 | # get all enabled users (Max 1M users) 25 | $users= get-msolUser -EnabledFilter EnabledOnly -MaxResults 1000000 26 | 27 | "Checking if " + $users.count + " users have the AAD_PREMIUM License" 28 | "if Not, then this script will assign licenses to users from a pool of " + $availableUnits + " available AAD_PREMIUM licenses." 29 | 30 | #count used for Uses successfully assigned a AAD_PREMIUM license 31 | $countOfUsersAssignedAadpLicense = 0; 32 | 33 | foreach($user in $users) 34 | { 35 | $isLicensedWithAADP = $false 36 | foreach ($lic in $user.licenses) 37 | { 38 | if($lic.AccountSkuid -ilike "*AAD_PREMIUM*") 39 | { 40 | $isLicensedWithAADP = $true 41 | } 42 | } 43 | 44 | # Add AAD Premium license to unlicensed users 45 | if ($isLicensedWithAADP -eq $false) 46 | { 47 | # if user's usage location is null, then update it using the company's countryCode - 48 | # the Users' usageLocation is required for license assignment 49 | # 50 | if ($user.usageLocation -eq $null) 51 | { 52 | set-msoluser -UserPrincipalName $user.userPrincipalName -usageLocation $defaultCompanyCountryCode 53 | } 54 | 55 | # try assigning AADP license to the user 56 | Try 57 | { 58 | Set-msolUserLicense -UserPrincipalName $user.userPrincipalName -AddLicenses $sku.AccountSkuid 59 | 60 | # decrement the avaialableUnits count 61 | --$availableUnits 62 | 63 | # increment the number of users assigned an AADP license 64 | ++$countOfUsersAssignedAadpLicense 65 | "AAD_PREMIUM license assigned to " + $user.userPrincipalName + " " + $user.displayName 66 | } 67 | 68 | Catch 69 | { 70 | "ERROR attempting to assign AAD_PREMIUM license to user " + $user.userPrincipalName 71 | } 72 | 73 | # exit when all available AAD_PREMIUM liceses have been assigned 74 | if ($availableUnits -eq 0) 75 | { 76 | "All availalable AAD_PREMIUM licenses have been assigned" 77 | exit 78 | } 79 | } 80 | } 81 | 82 | "Total number of users assigned an AAD_PREMIUM license: " + $countOfUsersAssignedAadpLicense 83 | 84 | 85 | -------------------------------------------------------------------------------- /Assign_AADPREMIUM_LicenseToFilteredUsers.ps1: -------------------------------------------------------------------------------- 1 | # this script assigns the AAD_PREMIUM license to a filtered list of users who do not currently have the AAD_PREMIUM license. 2 | # examples are shown below as possible user filters 3 | 4 | # Authenticate the Administrator 5 | $cred = get-credential 6 | connect-msolservice -credential $cred 7 | 8 | 9 | # get the country's registered countryCode, use as users' default usageLocation if this propery is not set on users 10 | # usage location is required for each user to be licensed 11 | $tenant = Get-MsolCompanyInformation 12 | $defaultCompanyCountryCode = $tenant.CountryLetterCode 13 | 14 | #get the tenant's AAD Premium SKU 15 | $sku=Get-MsolAccountSku | where{$_.SkuPartNumber -ilike "AAD_PREMIUM"} 16 | 17 | # check the available unit count - if zero, then exit the script 18 | $availableUnits = $sku.ActiveUnits - $sku.ConsumedUnits 19 | if ($availableUnits -eq 0) 20 | { 21 | "You have No avaialable AAD_PREMIUM licenses" 22 | exit 23 | } 24 | 25 | # the following are example of various filters 26 | # this filters for users who have their departnment property containing "IT" 27 | $users= get-msolUser -EnabledFilter EnabledOnly -MaxResults 1000000 | where{$_.department -ilike "*IT*"} 28 | 29 | # this filters for users who have their office property containing "New York" 30 | # $users= get-msolUser -EnabledFilter EnabledOnly -MaxResults 1000000 | where{$_.office -ilike "*New York*"} 31 | 32 | 33 | # this filters for users who have title containing "Marketing" and in the state that contains "NY" 34 | # $users= get-msolUser -EnabledFilter EnabledOnly -MaxResults 1000000 | where{$_.title -ilike "*Marketing*" -And $_.state -ilike "*NY*"} 35 | 36 | 37 | "Checking if " + $users.count + " users have the AAD_PREMIUM License" 38 | "if Not, then this script will assign licenses to users from a pool of " + $availableUnits + " available AAD_PREMIUM licenses." 39 | 40 | #count used for Uses successfully assigned a AAD_PREMIUM license 41 | $countOfUsersAssignedAadpLicense = 0; 42 | 43 | foreach($user in $users) 44 | { 45 | $isLicensedWithAADP = $false 46 | foreach ($lic in $user.licenses) 47 | { 48 | if($lic.AccountSkuid -ilike "*AAD_PREMIUM*") 49 | { 50 | $isLicensedWithAADP = $true 51 | } 52 | } 53 | 54 | # Add AAD Premium license to unlicensed users 55 | if ($isLicensedWithAADP -eq $false) 56 | { 57 | # if user's usage location is null, then update it using the company's countryCode - 58 | # the Users' usageLocation is required for license assignment 59 | # 60 | if ($user.usageLocation -eq $null) 61 | { 62 | set-msoluser -UserPrincipalName $user.userPrincipalName -usageLocation $defaultCompanyCountryCode 63 | } 64 | 65 | # try assigning AADP license to the user 66 | Try 67 | { 68 | Set-msolUserLicense -UserPrincipalName $user.userPrincipalName -AddLicenses $sku.AccountSkuid 69 | 70 | # decrement the avaialableUnits count 71 | --$availableUnits 72 | 73 | # increment the number of users assigned an AADP license 74 | ++$countOfUsersAssignedAadpLicense 75 | "AAD_PREMIUM license assigned to " + $user.userPrincipalName + " " + $user.displayName 76 | } 77 | 78 | Catch 79 | { 80 | "ERROR attempting to assign AAD_PREMIUM license to user " + $user.userPrincipalName 81 | } 82 | 83 | # exit when all available AAD_PREMIUM liceses have been assigned 84 | if ($availableUnits -eq 0) 85 | { 86 | "All availalable AAD_PREMIUM licenses have been assigned" 87 | exit 88 | } 89 | } 90 | } 91 | 92 | "Total number of users assigned an AAD_PREMIUM license: " + $countOfUsersAssignedAadpLicense 93 | 94 | 95 | -------------------------------------------------------------------------------- /Assign_AADPREMIUM_LicenseToUsersFromCSV.ps1: -------------------------------------------------------------------------------- 1 | # this script assigns the AAD_PREMIUM license to users read from a file: userList.csv file 2 | 3 | # Authenticate the Administrator 4 | $cred = get-credential 5 | connect-msolservice -credential $cred 6 | 7 | # read userList.csv file from a designated filepath 8 | $file = import-csv .\UserList.csv 9 | 10 | 11 | # get the country's registered countryCode, use as users' default usageLocation if this propery is not set on users 12 | # usage location is required for each user to be licensed 13 | $tenant = Get-MsolCompanyInformation 14 | $defaultCompanyCountryCode = $tenant.CountryLetterCode 15 | 16 | #get the tenant's AAD Premium SKUs 17 | $sku=Get-MsolAccountSku | where{$_.SkuPartNumber -ilike "AAD_PREMIUM"} 18 | 19 | # check the available unit count - if zero, then exit the script 20 | $availableUnits = $sku.ActiveUnits - $sku.ConsumedUnits 21 | if ($availableUnits -eq 0) 22 | { 23 | "You have No avaialable AAD_PREMIUM licenses" 24 | exit 25 | } 26 | 27 | #count used for Users successfully assigned a AAD_PREMIUM license 28 | $countOfUsersAssignedAadpLicense = 0; 29 | 30 | # read userList.csv file from a designated filepath 31 | $file = import-csv .\UserList.csv 32 | 33 | foreach($user in $file) 34 | { 35 | # read the current user's settings 36 | $retrievedUser = get-msoluser -userPrincipalName $user.userPrincipalName 37 | 38 | $isLicensedWithAADP = $false 39 | foreach ($lic in $retrievedUser.licenses) 40 | { 41 | if($lic.AccountSkuid -ilike "*AAD_PREMIUM*") 42 | { 43 | $isLicensedWithAADP = $true 44 | } 45 | } 46 | 47 | # Add AAD Premium license to unlicensed users 48 | if ($isLicensedWithAADP -eq $false) 49 | { 50 | # if user's usage location is null, then update it using the value from the userList.csv file 51 | # Note: the Users' usageLocation is required for license assignment 52 | # 53 | if ($retrievedUser.usageLocation -eq $null) 54 | { 55 | set-msoluser -UserPrincipalName $user.userPrincipalName -usageLocation $user.usageLocation 56 | } 57 | 58 | # try assigning AADP license to the user 59 | Try 60 | { 61 | # Set-msolUserLicense -UserPrincipalName $user.userPrincipalName -AddLicenses $sku.AccountSkuid 62 | Set-msolUserLicense -UserPrincipalName $user.userPrincipalName -AddLicenses $sku.AccountSkuid 63 | 64 | # decrement the avaialableUnits count 65 | --$availableUnits 66 | 67 | # increment the number of users assigned an AADP license 68 | ++$countOfUsersAssignedAadpLicense 69 | "AAD_PREMIUM license assigned to " + $user.userPrincipalName + " " + $user.displayName 70 | } 71 | 72 | Catch 73 | { 74 | "ERROR attempting to assign AAD_PREMIUM license to user " + $user.userPrincipalName 75 | } 76 | 77 | # exit when all available AAD_PREMIUM liceses have been assigned 78 | if ($availableUnits -eq 0) 79 | { 80 | "All availalable AAD_PREMIUM licenses have been assigned" 81 | exit 82 | } 83 | } 84 | } 85 | 86 | "Total number of users assigned an AAD_PREMIUM license: " + $countOfUsersAssignedAadpLicense 87 | 88 | 89 | -------------------------------------------------------------------------------- /ProvisionUsersAndAssignLicenseFromUserListCsv.ps1: -------------------------------------------------------------------------------- 1 | <# 2 | This script provisions new users int Azure AD from UserList.csv file, with userPrincipalName,displayName,password,usageLocation,licenseToAssign 3 | #> 4 | 5 | # Authenticate the Administrator 6 | $cred = get-credential 7 | connect-msolservice -credential $cred 8 | 9 | # read input.csv file from a designated filepath 10 | $file = import-csv .\UserList.csv 11 | 12 | # counter used to display the number of users processes 13 | $numberOfUsersProcessed = 0; 14 | 15 | # process each input.csv line item: userPrincpalName,displayName and password 16 | foreach ($user in $file) 17 | { 18 | # display values from each line 19 | $user.userPrincipalName + " " + $user.DisplayName + " " + $user.password 20 | 21 | # provision a new user, which geneate a random temp password 22 | New-MsolUser -UserPrincipalName $user.userPrincipalName -DisplayName $user.displayName -StrongPasswordRequired $false -usageLocation $user.usageLocation 23 | 24 | # set the newly created user's initial (temp) password, and require the user to reset it during initial logon 25 | Set-MsolUserPassword -UserPrincipalName $user.userPrincipalName -NewPassword $user.password -ForceChangePassword $true 26 | 27 | # assign License 28 | Set-MsolUserLicense -UserPrincipalName $user.userPrincipalName -AddLicenses $user.licenseToAssign 29 | 30 | 31 | # display number of users processes 32 | ++$numberOfUsersProcessed 33 | $numberOfUsersProcessed 34 | } 35 | 36 | # end of script -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Azure-ActiveDirectory-PowerShell-For-Admins 2 | =========================================== 3 | 4 | This repository contains PS1 powerShell Scripts for common Azure Active Directory Administrative tasks. 5 | 6 | * ProvisionUsersAndAssignLicenseFromUserListCsv.ps1 - PS1 powerShell script provisions new users, and assigns the AAD_Premium License. A temporary password assigned to each new user 7 | 8 | * Assign_AADPREMIUM_LicenseToAllUsers.ps1 - PS1 powerShell script will find all users who do not have the AAD_PREMIUM license assigned, and assign it to all users in the company (or until available AAD_PREMIUM licenses are consumed). 9 | 10 | * Assign_AADPREMIUM_LicenseToUsersFromCSV.ps1 - PS1 powerShell script will read a list of users from UserList.csv, and assign the AAD_PREMIUM license to users who do not currently have the license. 11 | 12 | 13 | ## Community Help and Support 14 | 15 | We leverage [Stack Overflow](http://stackoverflow.com/) to work with the community on supporting Azure Active Directory and its SDKs, including this one! We highly recommend you ask your questions on Stack Overflow (we're all on there!) Also browser existing issues to see if someone has had your question before. 16 | 17 | We recommend you use the "adal" tag so we can see it! Here is the latest Q&A on Stack Overflow for ADAL: [http://stackoverflow.com/questions/tagged/adal](http://stackoverflow.com/questions/tagged/adal) 18 | 19 | ## Security Reporting 20 | 21 | If you find a security issue with our libraries or services please report it to [secure@microsoft.com](mailto:secure@microsoft.com) with as much detail as possible. Your submission may be eligible for a bounty through the [Microsoft Bounty](http://aka.ms/bugbounty) program. Please do not post security issues to GitHub Issues or any other public site. We will contact you shortly upon receiving the information. We encourage you to get notifications of when security incidents occur by visiting [this page](https://technet.microsoft.com/en-us/security/dd252948) and subscribing to Security Advisory Alerts. 22 | 23 | ## We Value and Adhere to the Microsoft Open Source Code of Conduct 24 | 25 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 26 | -------------------------------------------------------------------------------- /RELEASES.md: -------------------------------------------------------------------------------- 1 | # Microsoft Identity SDK Versioning and Servicing FAQ 2 | 3 | We have adopted the semantic versioning flow that is industry standard for OSS projects. It gives the maximum amount of control on what risk you take with what versions. If you know how semantic versioning works with node.js, java, and ruby none of this will be new. 4 | 5 | ##Semantic Versioning and API stability promises 6 | 7 | Microsoft Identity libraries are independent open source libraries that are used by partners both internal and external to Microsoft. As with the rest of Microsoft, we have moved to a rapid iteration model where bugs are fixed daily and new versions are produced as required. To communicate these frequent changes to external partners and customers, we use semantic versioning for all our public Microsoft Identity SDK libraries. This follows the practices of other open source libraries on the internet. This allows us to support our downstream partners which will lock on certain versions for stability purposes, as well as providing for the distribution over NuGet, CocoaPods, and Maven. 8 | 9 | The semantics are: MAJOR.MINOR.PATCH (example 1.1.5) 10 | 11 | We will update our code distributions to use the latest PATCH semantic version number in order to make sure our customers and partners get the latest bug fixes. Downstream partner needs to pull the latest PATCH version. Most partners should try lock on the latest MINOR version number in their builds and accept any updates in the PATCH number. 12 | 13 | Examples: 14 | Using Cocapods, the following in the podfile will take the latest ADALiOS build that is > 1.1 but not 1.2. 15 | ``` 16 | pod 'ADALiOS', '~> 1.1' 17 | ``` 18 | 19 | Using NuGet, this ensures all 1.1.0 to 1.1.x updates are included when building your code, but not 1.2. 20 | 21 | ``` 22 | 26 | ``` 27 | 28 | | Version | Description | Example | 29 | |:-------:|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------:|:---------------------------------------------------------------------------------------------------------:| 30 | | x.x.x | PATCH version number. Incrementing these numbers is for bug fixes and updates but do not introduce new features. This is used for close partners who build on our platform release (ex. Azure AD Fabric, Office, etc.),In addition, Cocoapods, NuGet, and Maven use this number to deliver the latest release to customers.,This will update frequently (sometimes within the same day),There is no new features, and no regressions or API surface changes. Code will continue to work unless affected by a particular code fix. | ADAL for iOS 1.0.10,(this was a fix for the Storyboard display that was fixed for a specific Office team) | 31 | | x.x | MINOR version numbers. Incrementing these second numbers are for new feature additions that do not impact existing features or introduce regressions. They are purely additive, but may require testing to ensure nothing is impacted.,All x.x.x bug fixes will also roll up in to this number.,There is no regressions or API surface changes. Code will continue to work unless affected by a particular code fix or needs this new feature. | ADAL for iOS 1.1.0,(this added WPJ capability to ADAL, and rolled all the updates from 1.0.0 to 1.0.12) | 32 | | x | MAJOR version numbers. This should be considered a new, supported version of Microsoft Identity SDK and begins the Azure two year support cycle anew. Major new features are introduced and API changes can occur.,This should only be used after a large amount of testing and used only if those features are needed.,We will continue to service MAJOR version numbers with bug fixes up to the two year support cycle. | ADAL for iOS 1.0,(our first official release of ADAL) | 33 | 34 | 35 | 36 | ## Serviceability 37 | 38 | When we release a new MINOR version, the previous MINOR version is abandoned. 39 | 40 | When we release a new MAJOR version, we will continue to apply bug fixes to the existing features in the previous MAJOR version for up to the 2 year support cycle for Azure. 41 | Example: We release ADALiOS 2.0 in the future which supports unified Auth for AAD and MSA. Later, we then have a fix in Conditional Access for ADALiOS. Since that feature exists both in ADALiOS 1.1 and ADALiOS 2.0, we will fix both. It will roll up in a PATCH number for each. Customers that are still locked down on ADALiOS 1.1 will receive the benefit of this fix. 42 | 43 | ## Microsoft Identity SDKs and Azure Active Directory 44 | 45 | Microsoft Identity SDKs major versions will maintain backwards compatibility with Azure Active Directory web services through the support period. This means that the API surface area defined in a MAJOR version will continue to work for 2 years after release. 46 | 47 | We will respond to bugs quickly from our partners and customers submitted through GitHub and through our private alias (tellaad@microsoft.com) for security issues and update the PATCH version number. We will also submit a change summary for each PATCH number. 48 | Occasionally, there will be security bugs or breaking bugs from our partners that will require an immediate fix and a publish of an update to all partners and customers. When this occurs, we will do an emergency roll up to a PATCH version number and update all our distribution methods to the latest. 49 | -------------------------------------------------------------------------------- /UserList.csv: -------------------------------------------------------------------------------- 1 | userPrincipalName,displayName,password,usageLocation, licenseToAssign 2 | x4@graphDir1.onMicrosoft.com, X3 User, tempPa$$word, US, GraphDir1:AAD_PREMIUM 3 | x5@graphDir1.onMicrosoft.com, X3 User, tempPa$$word, US, GraphDir1:AAD_PREMIUM 4 | x6@graphDir1.onMicrosoft.com, X3 User, tempPa$$word, US, GraphDir1:AAD_PREMIUM 5 | --------------------------------------------------------------------------------