If you are unsure on how to connect to your instance of Office 365, please see my other blog post on connecting: Connect to Office365
First, you need to find your AccountSKUID
Get-MsolAccountSku
This will return a column called AccountSkuID. You will insert this into the script below where you see the term AccountSkuID.
This example shows how you can feed a list of existing users via a txt or csv file. The file I use only has one column with no header. This list contains the user ID portion of the user's email address only. For example if the user's email address is 12345@mydomain.com, the user ID is 12345.
import-module msonline
$Username = "admin@yourdomain.com"
$Password = ConvertTo-SecureString 'P@$$w0rd' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential $Username, $Password
connect-msolservice -credential $cred
$users = Get-Content c:\scripts\msolusers.csv
foreach($user in $users){
set-msoluserlicense -userprincipalname $user@yourdomain.com -addlicenses AccountSkuID:OFFICESUBSCRIPTION
}
Alternatively, if you'd like to license all user's who are currently in your Office 365 system, use the following script:
import-module msonline
$Username = "admin@yourdomain.com"
$Password = ConvertTo-SecureString 'P@$$w0rd' -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential $Username, $Password
connect-msolservice -credential $cred
$users = Get-MsolUser -all | select userprincipalname
foreach($user in $users){
set-msoluserlicense -userprincipalname $user -addlicenses AccountSkuID:OFFICESUBSCRIPTION
}
Disclaimer: All scripts and other powershell references on this blog are offered "as is" with no warranty. While these scripts are tested and working in my environment, it is recommended that you test these scripts in a test environment before using in your production environment.
No comments:
Post a Comment