Made a powershell script to replace or add user licenses based on the same csv that were used for Exchange Hybrid migration.
First You need a csv to be like this, but probably You have it if You did a migration.
In the first part, I used a script from AdminDroid (on excellent audit and reporting tool btw) and modified it a bit, just a bit. The modified script can be download with the script and put to a file called connect365services.ps1
1 2 3 4 5 6 7 8 9 |
clear-host write-host "Downloading Connect All O365 Services script." -foregroundcolor Green Invoke-WebRequest -Uri 'https://pilvi.sharepoint.com/:u:/s/External/ERWkkFHTCL1Hn5meyET0i0QBl9ohY3PBkQfPqfzBWFydDA?e=E7h7KH' -OutFile ConnectO365Services.ps1 "" write-host "Enter Global Admin credentials with or without MFA. If MFA needed, will transfer to Modern Auth prompt." -foregroundcolor Green "" ./ConnectO365Services.ps1 clear-host "" |
The original one here https://admindroid.sharepoint.com/:u:/s/external/ETYww6L3LJFJooEb5MOwjrkBJrHNhGb-EUK5ZBFPiMfm_A?e=Hb9fb4
Then I added a menu for license assignements or for quitting to Powershell. If You quit You can still use all the connected sessions.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
function Show-Menu { param ( [string]$Title = 'Please choose an option below' ) Clear-Host Write-Host "$Title" -foregroundcolor yellow "" Write-Host "1: Press '1' for adding or replacing licenses." Write-Host "2: Press 'Q' for Powershell prompt" } do { Show-Menu "" $selection = Read-Host "Please make a selection" switch ($selection) |
After You choose to replace licenses, You will see all the Skus in the tenant and You will be given a directory listing to find the csv-file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
$AllSkus = get-msolaccountsku write-host 'List All Skus:' -foregroundcolor green "" $AllSkus.AccountSkuId | FL | Out-String | Write-Host -foregroundcolor yellow $sku = Read-Host -Prompt 'Enter Sku name to use for licenses' "" #Define the SKU to Add $SKUsToAdd = @("$sku") #Import users from CSV file dir "" $CsvFile = Read-Host -Prompt 'CSV filename' $MyUsers = import-csv $csvfile "" |
Then the script will add location to FI in my case, change accordingly.
And here is the full script with menus.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
clear-host write-host "Downloading Connect All O365 Services script." -foregroundcolor Green Invoke-WebRequest -Uri 'https://pilvi.sharepoint.com/:u:/s/External/ERWkkFHTCL1Hn5meyET0i0QBl9ohY3PBkQfPqfzBWFydDA?e=E7h7KH' -OutFile ConnectO365Services.ps1 "" write-host "Enter Global Admin credentials with or without MFA. If MFA needed, will transfer to Modern Auth prompt." -foregroundcolor Green "" ./ConnectO365Services.ps1 clear-host "" function Show-Menu { param ( [string]$Title = 'Please choose an option below' ) Clear-Host Write-Host "$Title" -foregroundcolor yellow "" Write-Host "1: Press '1' for adding or replacing licenses." Write-Host "2: Press 'Q' for Powershell prompt" } do { Show-Menu "" $selection = Read-Host "Please make a selection" switch ($selection) { '1' { "" $AllSkus = get-msolaccountsku write-host 'List All Skus:' -foregroundcolor green "" $AllSkus.AccountSkuId | FL | Out-String | Write-Host -foregroundcolor yellow $sku = Read-Host -Prompt 'Enter Sku name to use for licenses' "" #Define the SKU to Add $SKUsToAdd = @("$sku") #Import users from CSV file dir "" $CsvFile = Read-Host -Prompt 'CSV filename' $MyUsers = import-csv $csvfile "" write-host "Settings licenses and Location:" -foregroundcolor Green "" #Replace Skus for users foreach($user in $MyUsers){ $userupn = (get-mailbox $user.emailaddress | get-msoluser).UserPrincipalName set-msoluser -UserPrincipalName $Userupn -usagelocation FI write-host Location for $User.emailaddress has been set to Finland. -foregroundcolor Green write-host "-------------------------------------------------------" $CurrentSKUs = (Get-MsolUser -UserPrincipalName $Userupn).Licenses.AccountSKUID write-host $User.emailaddress has $CurrentSKUs license. -foregroundcolor Green $NewSKUs = $SKUsToAdd | where {$CurrentSKUs -NotContains $_} If ($NewSKUs) { Set-MSOLUserLicense -UserPrincipalName $Userupn -AddLicenses $NewSKUs write-host $User.emailaddress has been assigned $CurrentSKUs license -foregroundcolor Green write-host "-------------------------------------------------------" } } } } pause } until ($selection -eq 'q') |