Office 365 provides a very feature rich admin center that allows easy management and configuration of users, licenses, and subscribed services. There are some cases, however, that require bulk operations such as assigning licenses, setting permissions, or putting mailboxes on litigation hold. In those cases, PowerShell can become a critical component to help reduce the manual processes by scripting them into an automated solution.
Below are the four different services in Office 365 that PowerShell can manage:
- Windows Azure Active Directory – This provides the ability to manage users, groups, licenses, single sign-on, domains, and general tenant information.
- Exchange Online – This provides the ability to manage mailboxes, permissions, compliance, domains and generate reports.
- SharePoint Online – This provides the ability to manage sites, groups, and permissions.
- Lync Online – This provides the ability to manage users and policies.
Getting started with PowerShell to manage the services listed above can be a bit confusing. Each of the services has different software pre-requisites and methods for connecting to the services. In the rest of this post, I will outline how to get started with PowerShell for each of the four services listed.
Windows Azure Active Directory
Windows Azure Active Directory is the service that manages all of the users, groups, and licensing for the Office 365 environment. This service also provides the features for single sign-on that some larger organizations choose to implement.
To get started with PowerShell for Windows Azure Active Directory you will need to install some software prerequisites on a supported operating system. Currently Windows 7, Windows 8, Windows Server 2008 R2 and Windows Server 2012 are supported. Ensure that each of the following prerequisites are installed:
Once all of the prerequisites are installed, you can begin using PowerShell to manage your Office 365 users, groups and licenses. Before you can run any of the PowerShell cmdlets for Windows Azure Active Directory, you must first connect to the online service. This is accomplished by running the connect-msolservice cmdlets at the Windows PowerShell command prompt as demonstrated below.
$msolcred = get-credential
Connect-msolservice –credential $msolcred
Now that you are connected to the online service, you can use any of the Windows Azure Active Directory cmdlets. For a list of available cmdlets you can reference the TechNet article titled Manage Windows Azure AD using Windows Powershell.
Exchange Online provides administrators the ability to manage almost every aspect of the service using PowerShell. Getting started with PowerShell for Exchange Online is very simple and does not require the installation of any additional prerequisites. Instead, a remote PowerShell session is created that will automatically create local proxy cmdlets that you can use for interacting with the service. To get started, you need to open up Windows PowerShell and create a new remote PowerShell session to Exchange Online by using the below commands:
$cred = get-credential
$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $cred -Authentication Basic –AllowRedirection
After running these commands, you will see PowerShell creating local proxy cmdlets for the remote PowerShell session. Once the process completes you can begin using any of the Exchange Online Powershell cmdlets. After you finish using the remote PowerShell session, you should always disconnect by using the command shown below.
For a list of available Exchange Online cmdlets you can reference the article titled Reference to Available PowerShell Cmdlets in Exchange Online.
The PowerShell cmdlets available for SharePoint Online allows an Office 365 global administrator to do basic tasks such as creating sites and managing permissions. Before you get started, you must install the SharePoint Online Management Shell, which can be downloaded from the Microsoft Download Center.
To connect to the SharePoint Online environment with PowerShell, open the SharePoint Online Management Shell you just installed and run the following cmdlet:
Connect-SPOService –url https://mysite-admin.sharepoint.com –credential firstname.lastname@example.org
Make sure you replace the URL and the credential with the appropriate values for your SharePoint Online tenant. URL is the URL of your SharePoint Online Administration center and not the address that your end user access. Credential is the user name of the person who is an Office 365 global administrator.
Now that you are connected to SharePoint Online using PowerShell you can use any of the available cmdlets. A list of available SharePoint Online PowerShell cmdlets can be found in the TechNet article titled Introduction to the SharePoint Online Management Shell.
Lync Online is the IM, Presence, Audio, Video and web conferencing solution available in Office 365. PowerShell can be used to manage aspects of this service including users, policies, and Lync client configuration.
To get started with PowerShell for Lync Online you will need to install some software prerequisites on a supported 64-bit operating system. Currently Windows 7, Windows 8, Windows Server 2008 R2 and Windows Server 2012 are supported. Ensure that each of the following prerequisites are installed:
Once all of the prerequisites have been installed you can begin using the PowerShell with Lync Online. Begin by opening a Windows PowerShell Command Prompt and entering in the following commands, which will start a remote PowerShell session:
$credential = get-credential
$session = New-CsOnlineSession –Credential $credential
Once the remote PowerShell session is established, you can use any of the available Lync Online PowerShell cmdlets. A list of the available cmdlets can be found in the TechNet article titled The Lync Online Cmdlets.
Just like with Exchange Online, when finished you must disconnect from the remote Lync Online PowerShell session using the following command:
If you forget to use the above command to disconnect from the session it will automatically be closed after 15 minutes of inactivity. It is important to remember that an administrator is limited to three simultaneous sessions connected to Lync Online.
As you see getting started with PowerShell for Office 365 is not difficult, it just requires some initial setup and an understanding of how each of the services interact with PowerShell. Using PowerShell an administrator can setup solutions to automate many of the manual and repetitive tasks.