Showing posts with label office 365. Show all posts
Showing posts with label office 365. Show all posts

Tuesday, May 19, 2015

Office 365 - Licensing Users in Bulk

If you've signed your business up for Office 365, you are probably well aware of their license offerings and that you must assign them to users as you go.  You may be using a variety of licenses such as the Exchange Standard license or the Office Subscription license.  If you automate user creation, you can add a license at creation time or after they are already created.  In this example, I'll show how to license user's who are already created.

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.

Wednesday, August 27, 2014

How to Connect to Office 365


In this post, I am going to simply discuss how to connect to Office 365 using Powershell.  With Powershell, you can manage and automate several tasks in Office 365, which will make your life much easier.  Some of the tasks I have automated are user account creation, distribution group memberships, and licensing.  I will outline connecting to Microsoft Online, where you can manage items such as accounts and licensing.  I will also cover how to connect to Exchange Online, which is more directed at mailbox related tasks.

Required Components

Before connecting, you'll need to install 2 components on your PC: the Microsoft Online (MSOL) Sign in Assistant, and the Azure Active Directory Module.  Keep in mind, the MSOL Sign in Assistant must be installed before you can install the Azure AD Module.  Here is where these can be obtained:


MSOL Sign in Assistant
Azure AD Module



Making the Connection

After you have finished installing the required components, open a new Powershell session.  The first thing we are going to do is import the MSOL module.


 import-module msonline  

Next, we need to initiate the connection.


 connect-msolservice  

You will be prompted for your Office 365 administrator login credentials.



Connecting to Exchange Online

Again, Exchange Online is useful for more mailbox related functions.  If you need to add a user to a distribution group, this is where you'll turn.  First, we need to capture the administrator credentials for your Exchange Online domain.  You will be prompted for your username and password.


 $credential = get-credential  


Next, lets store the session cmdlet in a variable called $Session.


 $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $credential -Authentication Basic -AllowRedirection  

Now, we initiate the session.


 Import-PSSession $Session  

When you're finished with your session, it's a good idea to disconnect gracefully.  I'm not sure what the default connection time-window is for Exchange Online, but I do know there is a small limit to the number of simultaneous connections you can have open for your domain.  If you have to many sessions open that you didn't disconnect, you won't be able to reconnect for a duration of time.  Here's how to disconnect:


 remove-pssession $Session  


That's all there is to connecting to Office 365.  I hope to add more posts centered around Office 365 in the near future that will show you how perform everyday tasks and setup some automation.