Powershell
Powershell
Summary: Learn how to use Office 365 PowerShell with Office 365 users and licenses, Skype for Business
Online, SharePoint Online, Exchange Online, and the Office 365 Security & Compliance Center.
Office 365 PowerShell is a powerful management tool that complements the Microsoft 365 admin center. For
example, you can use Office 365 PowerShell automation to more quickly manage multiple user accounts and
licenses and create reports. Learn how to use Office 365 PowerShell with Office 365 users and licenses, Skype
for Business Online, SharePoint Online, Exchange Online, and the Office 365 Security & Compliance Center.
Select the topic based on your needs:
Getting started with Office 365 PowerShell
Start here if you are not familiar with Office 365 PowerShell and want to install the Office 365
PowerShell modules and connect to your Office 365 tenant.
Manage user accounts and licenses with Office 365 PowerShell
Start here if you have installed the Office 365 PowerShell modules and want to learn more about using
automation commands to manage user accounts and licenses.
Office 365 PowerShell for SharePoint Online
Start here if you have installed the Office 365 PowerShell modules and want to use automation
commands to perform management of SharePoint Online.
Exchange Online PowerShell
Start here if you want to use automation commands to manage Exchange Online.
Use PowerShell for email migration to Office 365
Start here if you have installed the Office 365 PowerShell modules and want to migrate your email from
existing systems.
Office 365 Security & Compliance Center PowerShell
Start here if you want to use automation commands to manage the Security & Compliance Center.
Manage Office 365 with Windows PowerShell for Delegated Access Permissions (DAP ) partners
Start here if you want to use Syndication and Cloud Solution Provider (CSP ) partners to manage your
Office 365 customer tenants.
Manage Skype for Business Online with Office 365 PowerShell
Start here if you have installed the Office 365 PowerShell modules and want to perform management of
Skype for Business Online.
Skype for Business Online cmdlets
Start here if you are very comfortable with Office 365 PowerShell and want to learn more about specific
commands to manage dial-in conferencing, Cloud PBX, and PSTN calling settings for your organization,
and use the reporting features to monitor and report on Skype for Business Online usage.
Getting started with Office 365 PowerShell
5/15/2019 • 2 minutes to read • Edit Online
Summary: Understand the importance of Office 365 PowerShell, get connected to your Office 365 tenant, and
get help.
With Office 365 PowerShell, you can manage Office 365 with commands and scripts to streamline your daily
work. Learn why Office 365 PowerShell skills are crucial to managing Office 365, how to connect to your Office
365 subscription, create reports, and get additional information and help from the Office 365 community.
Select the article based on your needs:
Why you need to use Office 365 PowerShell
Start here if you are brand new to Office 365 PowerShell and learn six reasons why you need to use
Office 365 PowerShell.
Connect to Office 365 PowerShell
Start here to connect to your Office 365 subscription using Office 365 PowerShell and perform
administrative tasks from the command line.
Connect to all Office 365 services in a single Windows PowerShell window
You can manage Office 365 in separate windows for Skype for Business Online, SharePoint Online,
Microsoft Exchange Online, and Office 365 accounts and licenses. Alternately, can manage these from a
single window. This topic tells you how.
Use Windows PowerShell to create reports in Office 365
Start here if you have installed the Office 365 PowerShell modules and want to learn more about using
automation commands to quickly create reports.
Cmdlet references for Office 365 services
Start here to find the topics that describe the cmdlets for the Office 365 PowerShell modules.
Office 365 PowerShell community resources
Start here to connect to the PowerShell community venues and get help or ongoing information about
using Office 365 PowerShell .
See also
Manage Office 365 with Office 365 PowerShell
Why you need to use Office 365 PowerShell
5/15/2019 • 18 minutes to read • Edit Online
Summary: Understand why you must use Office 365 PowerShell to manage Office 365, in some cases more
efficiently and in other cases by necessity.
With the Microsoft 365 admin center, you can not only manage your Office 365 user accounts and licenses, but
you can also manage your Office 365 server products: Exchange, Skype for Business Online, and SharePoint
Online. However, you can also manage these elements with Office 365 PowerShell commands, taking advantage
of a command-line and scripting language environment for speed, automation, and additional capability.
In this article, we'll show you these ways in which you can use Office 365 PowerShell to manage Office 365.
Office 365 PowerShell can reveal additional information that you cannot see with the Microsoft 365 admin
center
Office 365 has features that you can only configure by using Office 365 PowerShell
Office 365 PowerShell is great at performing bulk operations
Office 365 PowerShell is great at filtering data
Office 365 PowerShell makes it easy to print or save data
Office 365 PowerShell lets you manage across server products
Before you begin, understand that Office 365 PowerShell is a set of modules for Windows PowerShell, a
command-line environment for Windows-based services and platforms. This environment creates a command
shell language that can be extended with additional modules and provides a way to execute simple or complex
commands or scripts. For example, after you install the Office 365 PowerShell modules and connect to your Office
365 subscription, you can run this command to list all of the user mailboxes for Microsoft Exchange Online:
Get-Mailbox
Getting the list of mailboxes can also be easily done using the Microsoft 365 admin center, but counting the
number of items in all of the lists for all of the sites for all of your web apps cannot be easily done.
Please note that Office 365 PowerShell is designed to augment and enhance your ability to manage Office 365,
not to replace the Microsoft 365 admin center. As an Office 365 administrator, you must become at least
comfortable with using Office 365 PowerShell because there are some configuration procedures that can only be
done with Office 365 PowerShell commands. In these cases, you will be required to understand how to:
Install the Office 365 PowerShell modules (done only once for each administrator computer).
Connect to your Office 365 subscription (done once for each PowerShell session).
Gather the information needed to run the required Office 365 PowerShell commands.
Run the Office 365 PowerShell commands successfully.
After learning these basic skills, you are not required to list your mailbox users with Get-Mailbox command, nor
are you required to understand how to create a new command like the previous one to count all the items in all the
lists for all of the sites for all of your web apps. Microsoft and the community of Office 365 administrators can help
you with that as needed.
Office 365 PowerShell can reveal additional information that you
cannot see with the Microsoft 365 admin center
The Microsoft 365 admin center displays a lot of useful information, but that doesn't mean that it displays all the
possible information that Office 365 stores on users, licenses, mailboxes, and sites. Here is an example for users
and groups in the Microsoft 365 admin center:
For many purposes, this displays the information you need to know. However, there are times when you need
more. For example, Office 365 licensing (and the Office 365 features available to a user) depend in part on that
user's geographic location. The policies and features you can extend to a user who lives in the United States might
not be the same as the policies and features you can extend to a user who lives in India or in Belgium. You can use
the Microsoft 365 admin center to determine a user's geographic location with these steps:
1. Double-click the user's Display Name.
2. In the user properties display pane, click details.
3. In the details display, click additional details.
4. Scroll down until you see the heading Country or region:
5. Write the user's display name and location on a piece of paper, or copy and paste it into Notepad.
You must repeat this procedure for each user. For many users, this can be a tedious task. With Office 365
PowerShell, you can display this information for all of your users with the following command:
NOTE
This command requires you to install the Windows Azure Active Directory module.
TIP
The interpretation of this Office 365 PowerShell command is: Get all of the users in the current Office 365 subscription ( Get-
MsolUser ), but only display the name and location for each user ( Select DisplayName, UsageLocation ).
Because Office 365 PowerShell supports a command shell language, you can further manipulate the information
obtained from the Get-MSolUser command. For example, maybe you'd like to sort these users by their location,
grouping all the Brazilian users together, all the United States users together, etc. Here is the command:
DisplayName UsageLocation
----------- -------------
David Longmuir BR
Fabrice Canel BR
Bonnie Kearney GB
Alex Darrow US
Anne Wallace US
Brian Johnson (TAILSPIN) US
TIP
The interpretation of this Office 365 PowerShell command is: Get all of the users in the current Office 365 subscription, but
only display the name and location for each user and sort them first by their location, and then their names ( Sort
UsageLocation, DisplayName ).
You can also employ additional filtering. For example, if you only want to see information about users based in
Brazil, use this command:
DisplayName UsageLocation
----------- -------------
David Longmuir BR
Fabrice Canel BR
TIP
The interpretation of this Office 365 PowerShell command is: Get all of the users in the current Office 365 subscription whose
location is Brazil ( Where {$_.UsageLocation -eq "BR"} ), then display the name and location for each user.
That works great for smaller domains. In a large organization, however, you might need to split that into two
commands: one command to store the user account information in a variable and another command to display the
needed information. Here is an example:
$x = Get-MsolUser
$x | Select DisplayName, UsageLocation
Office 365 has features that you can only configure with Office 365
PowerShell
The Microsoft 365 admin center is intended to provide access to the most common or meaningful administrative
tasks that apply to most people. In other words, the Microsoft 365 admin center was designed so that the typical
administrator could use the tool to carry out the most common management tasks. By this definition, that means
that there are some tasks that can't be completed by using the Microsoft 365 admin center.
For example, the Skype for Business Online Admin center provides a few options for creating custom meeting
invitations:
With these settings, you can add a touch of personalization and professionalism to meeting invitations. However,
there's more to meeting configuration settings than simply creating custom meeting invitations. For example, by
default, meetings allow:
Anonymous users to gain automatic entrance to each meeting.
Attendees to record the meeting.
All users from your organization to be designated as presenters when they join the meeting.
These settings are not available from the Skype for Business Online Admin center. However, you can control them
from Office 365 PowerShell. Here is a command that disables these three settings:
NOTE
This command requires that you install the Skype for Business Online PowerShell Module .
TIP
The interpretation of this Office 365 PowerShell command is: For the settings for new Skype for Business Online meetings (
Set-CsMeetingConfiguration ), disable allowing anonymous users to gain automatic entrance to meetings ( -
AdmitAnonymousUsersByDefault $False ), disable the ability for attendees to record meetings ( -
AllowConferenceRecording $False ), and do not designate all users from your organization as presenters ( -
DesignateAsPresenter "None" ).
If you change your mind and want to restore these default settings (all of them enabled), run this command:
This is just one example. There are others, which is why you, as an Office 365 administrator, need to be
comfortable with running Office 365 PowerShell commands.
Office 365 PowerShell is great at carrying out bulk operations
Historically, visual interfaces like the Microsoft 365 admin center are most valuable when you have a single
operation to perform. For example, if you need to disable one user account, you can use the Microsoft 365 admin
center to quickly locate and clear a checkbox. This can be simpler than performing a similar operation in Office 365
PowerShell.
But if you have to change many things or some selected things within a large set of other things, the Microsoft 365
admin center might not be the best use of your time. For example, if you had to change the prefix on thousands of
phone numbers or you needed to remove a specific user, Ken Myer, from all of your SharePoint Online sites, how
would you do that in the Microsoft 365 admin center?
For the latter example, you have several hundred SharePoint Online sites and you don't know even know which
ones of which Ken Meyer is a member. That means you'll have to start at the Microsoft 365 admin center and then
perform this procedure for each site:
1. Click the URL of the site.
2. In the site collection properties box, click the Web Site Address link to open the site.
3. On the site, click Share.
4. In the Share dialog box click the link that shows you all the users who have permissions to the site:
TIP
The interpretation of this Office 365 PowerShell command is: Get all of the SharePoint sites in the current Office 365
subscription ( Get-SPOSite ) and for each site, remove Ken Meyer from the list of users who can access it ( ForEach
{Remove-SPOUser -Site $_.Url -LoginName "[email protected]"} ).
Because we are telling Office 365 to remove Ken Meyer from every site, including those in which he does not have
access, the display of this command will show errors for those sites in which he does not currently have access. We
can use an additional condition on this command to remove Key Meyer only from the sites that have him in their
login list, but the listed errors cause no harm to the sites themselves. This command might take a few minutes to
run against hundreds of sites, rather than hours of working through the Microsoft 365 admin center.
Here is another bulk operation example. Use this command to add Bonnie Kearney, a new SharePoint
administrator, to all of the sites in the organization:
TIP
The interpretation of this Office 365 PowerShell command is: Get all of the SharePoint sites in the current Office 365
subscription and for each site, allow Bonnie Kearney access by adding her login name to the Members group of the site (
ForEach {Add-SPOUser -Site $_.Url -LoginName "[email protected]" -Group "Members"} ).
Get-User | Where {$_.RecipientTypeDetails -eq "UserMailbox" -and ($_.City -eq "San Diego" -or $_.City -eq
"Bloomington")} | Select DisplayName, City
DisplayName City
----------- ----
Alex Darrow San Diego
Bonnie Kearney San Diego
Julian Isla Bloomington
Rob Young Bloomington
TIP
The interpretation of this Office 365 PowerShell command is: Get all of the users in the current Office 365 subscription who
have a mailbox in the cities of either San Diego or Bloomington ( Where {$_.RecipientTypeDetails -eq "UserMailbox" -
and ($_.City -eq "San Diego" -or $_.City -eq "Bloomington")} ), then display the name and city for each ( Select
DisplayName, City ).
To list all the mailboxes for people who live anywhere except Bloomington, here is the command:
Get-User | Where {$_.RecipientTypeDetails -eq "UserMailbox" -and $_.City -ne "Bloomington"} | Select
DisplayName, City
Here is an example of the display:
DisplayName City
----------- ----
MOD Administrator Redmond
Alex Darrow San Diego
Allie Bellew Bellevue
Anne Wallace Louisville
Aziz Hassouneh Cairo
Belinda Newman Charlotte
Bonnie Kearney San Diego
David Longmuir Waukesha
Denis Dehenne Birmingham
Garret Vargas Seattle
Garth Fort Tulsa
Janet Schorr Bellevue
TIP
The interpretation of this Office 365 PowerShell command is: Get all of the users in the current Office 365 subscription who
have a mailbox not located in the city of Bloomington ( Where {$_.RecipientTypeDetails -eq "UserMailbox" -and $_.City
-ne "Bloomington"} ), then display the name and city for each.
You can also use wildcard characters in your Office 365 PowerShell filters to match part of a name. For example,
suppose you're looking for a user account, and all you can remember is that their last name was Anderson, or
maybe Henderson, or maybe it was Jorgenson.
You could track down that user in the Microsoft 365 admin center by using the search tool and carrying out three
different searches:
One for Anderson
One for Henderson
One for Jorgenson
Because all three of these names end in "son", you can tell Office 365 PowerShell to display all the users whose
name ends in "son". Here is the command:
TIP
The interpretation of this Office 365 PowerShell command is: Get all of the users in the current Office 365 subscription, but
use a filter that only lists the users whose last names end in "son" ( -Filter '{LastName -like "*son"}' ). The * stands for any
set of characters, which are letters in the case of the user's last name.
You can also use options to save this list as an XML file or as an HTML page. In fact, with additional PowerShell
commands, you could save it directly as an Excel file, with any custom formatting you desire.
You can also send the output of an Office 365 PowerShell command that displays a list directly to the default
printer in Windows. Here is an example command:
TIP
The interpretation of this Office 365 PowerShell command is: Get all of the Skype for Business Online users in the current
Office 365 subscription, obtain only the user name, UPN, and location, and then send that information to the default
Windows printer ( Out-Printer ).
The printed document has the same simple formatting as the display within the Office 365 PowerShell command
window, but once you have created an Office 365 PowerShell command to list what you need, you just add | Out-
Printer to the end of the command to get a hard copy to work from.
$x = Get-MsolUser
See also
Getting started with Office 365 PowerShell
Manage user accounts and licenses with Office 365 PowerShell
Use Windows PowerShell to create reports in Office 365
Connect to Office 365 PowerShell
5/15/2019 • 5 minutes to read • Edit Online
Summary: Connect to your Office 365 organization using Office 365 PowerShell to perform administration tasks
from the command line.
Office 365 PowerShell lets you manage your Office 365 settings from the command line. Connecting to Office
365 PowerShell is a simple process where you install the required software and then connect to your Office 365
organization.
There are two versions of the PowerShell module that you use to connect to Office 365 and administer user
accounts, groups, and licenses:
Azure Active Directory PowerShell for Graph (cmdlets include AzureAD in their name)
Microsoft Azure Active Directory Module for Windows PowerShell (cmdlets include MSol in their name)
As of the date of this article, the Azure Active Directory PowerShell for Graph module does not completely replace
the functionality in the cmdlets of Microsoft Azure Active Directory Module for Windows PowerShell module for
user, group, and license administration. In many cases, you need to use both versions. You can safely install both
versions on the same computer.
TIP
New to PowerShell? See a video Overview of PowerShell, brought to you by LinkedIn Learning.
NOTE
Use a 64-bit version of Windows. Support for the 32-bit version the Microsoft Azure Active Directory
Module for Windows PowerShell was discontinued in October of 2014.
These procedures are intended for users who are members of an Office 365 admin role. For more
information, see About Office 365 admin roles.
Connect with the Azure Active Directory PowerShell for Graph module
Commands in the Azure Active Directory PowerShell for Graph module have AzureAD in their cmdlet name.
For procedures that require the new cmdlets in the Azure Active Directory PowerShell for Graph module, use
these steps to install the module and connect to your Office 365 subscription.
NOTE
See Azure Active Directory PowerShell for Graph module for information about the support for different versions of
Microsoft Windows.
If prompted about installing a module from an untrusted repository, type Y and press ENTER.
Step 2: Connect to Azure AD for your Office 365 subscription
To connect to Azure AD for your Office 365 subscription with an account name and password or with multi-factor
authentication (MFA ), run one of these commands from a Windows PowerShell command prompt (it does not
have to be elevated).
Office 365 U.S. Government DoD and Office 365 U.S. Connect-AzureAD -AzureEnvironmentName
Government GCC High AzureUSGovernment
In the Sign into your account dialog box, type your Office 365 work or school account user name and password,
and then click OK.
If you are using MFA, follow the instructions in the additional dialog boxes to provide more authentication
information, such as a verification code.
After connecting, you can use the new cmdlets for the Azure Active Directory PowerShell for Graph module.
Office 365 U.S. Government DoD and Office 365 U.S. Connect-MsolService -AzureEnvironment USGovernment
Government GCC High
In the Sign into your account dialog box, type your Office 365 work or school account user name and password,
and then click OK.
If you are using MFA, follow the instructions in the additional dialog boxes to provide more authentication
information, such as a verification code.
How do you know this worked?
If you don't receive any errors, you connected successfully. A quick test is to run an Office 365 cmdlet—for
example, Get-MsolUser —and see the results.
If you receive errors, check the following requirements:
A common problem is an incorrect password. Run Step 2 again. and pay close attention to the user
name and password you enter.
The Microsoft Azure Active Directory Module for Windows PowerShell requires that the
Microsoft .NET Framework 3.5.x feature is enabled on your computer. It's likely that your computer
has a newer version installed (for example, 4 or 4.5.x), but backwards compatibility with older versions of
the .NET Framework can be enabled or disabled. For more information, see the following topics:
For Windows Server 2012 or Windows Server 2012 R2, see Enable .NET Framework 3.5 by using
the Add Roles and Features Wizard
For Windows 7 or Windows Server 2008 R2, see You can't open the Azure Active Directory Module
for Windows PowerShell
For Windows 10, Windows 8.1, and Windows 8, see Install the .NET Framework 3.5 on Windows 10,
Windows 8.1, and Windows 8
Your version of the Microsoft Azure Active Directory Module for Windows PowerShell might be
out of date. To check, run the following command in Office 365 PowerShell or the Microsoft Azure Active
Directory Module for Windows PowerShell:
(Get-Item
C:\Windows\System32\WindowsPowerShell\v1.0\Modules\MSOnline\Microsoft.Online.Administration.Automation.
PSModule.dll).VersionInfo.FileVersion
If the version number returned is lower than the value 1.0.8070.2, uninstall the Microsoft Azure Active
Directory Module for Windows PowerShell and install the latest version from the link in Step 1.
If you receive a connection error, see this topic: "Connect-MsolService: Exception of type was thrown"
error.
See also
Manage Office 365 with Office 365 PowerShell
Getting started with Office 365 PowerShell
Connect to all Office 365 services in a single Windows PowerShell window
Get-Credential
Connect-MsolService
Connect to all Office 365 services in a single
Windows PowerShell window
5/15/2019 • 5 minutes to read • Edit Online
Summary: Instead of managing different Office 365 services in separate PowerShell console windows, you can
connect to all Office 365 services and manage them from single console window.
When you use PowerShell to manage Office 365, it is possible to have up to five different Windows PowerShell
sessions open at the same time corresponding to Microsoft 365 admin center, SharePoint Online, Exchange
Online, Skype for Business Online, and the Security & Compliance Center. With five different connection methods
in separate Windows PowerShell sessions, your desktop could look like this:
This is not optimal for managing Office 365 because you can't exchange data among those five windows for cross-
service management. This topic describes how to use a single instance of Windows PowerShell from which you
can manage Office 365, Skype for Business Online, Exchange Online, SharePoint Online, and the Security &
Compliance Center.
NOTE
This article currently only contains the commands to connect to the Office 365 Worldwide (+GCC) cloud. Additional notes
provide links to articles with information about connecting to the other Office 365 clouds.
Set-ExecutionPolicy RemoteSigned
$credential = Get-Credential
3. Run this command to connect to Azure Active Directory (AD ) using the Azure Active Directory PowerShell for
Graph module.
Alternately, if you are using the Microsoft Azure Active Directory Module for Windows PowerShell module, run
this command.
5. Run these commands to connect to Skype for Business Online. A warning about increasing the
WSMan NetworkDelayms value is expected the first time you connect and should be ignored.
Import-Module SkypeOnlineConnector
$sfboSession = New-CsOnlineSession -Credential $credential
Import-PSSession $sfboSession
NOTE
To connect to Exchange Online for Office 365 clouds other than Worldwide, see Connect to Exchange Online PowerShell.
NOTE
To connect to the Security & Compliance Center for Office 365 clouds other than Worldwide, see Connect to Office 365
Security & Compliance Center PowerShell.
Here are all the commands in a single block when using the Azure Active Directory PowerShell for Graph module.
Specify the name of your domain host, and then run them all at one time.
$orgName="<for example, litwareinc for litwareinc.onmicrosoft.com>"
$credential = Get-Credential
Connect-AzureAD -Credential $credential
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
Connect-SPOService -Url https://$orgName-admin.sharepoint.com -credential $credential
Import-Module SkypeOnlineConnector
$sfboSession = New-CsOnlineSession -Credential $credential
Import-PSSession $sfboSession
$exchangeSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri
"https://outlook.office365.com/powershell-liveid/" -Credential $credential -Authentication "Basic" -
AllowRedirection
Import-PSSession $exchangeSession -DisableNameChecking
$SccSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri
https://ps.compliance.protection.outlook.com/powershell-liveid/ -Credential $credential -Authentication
"Basic" -AllowRedirection
Import-PSSession $SccSession -Prefix cc
Alternately, here are all the commands in a single block when using the Microsoft Azure Active Directory Module
for Windows PowerShell module. Specify the name of your domain host, and then run them all at one time.
When you are ready to close down the Windows PowerShell window, run this command to remove the active
sessions to Skype for Business Online, Exchange Online, SharePoint Online, and the Security & Compliance
Center:
Alternately, here are all the commands when using the Microsoft Azure Active Directory Module for Windows
PowerShell module.
For Exchange Online and the Security & Compliance Center, see the following topics to connect using multi-factor
authentication:
Connect to Exchange Online PowerShell using multi-factor authentication
Connect to Office 365 Security & Compliance Center PowerShell using multi-factor authentication
Note that in both cases, you must connect using separate sessions of the Exchange Online Remote PowerShell
Module.
See also
Connect to Office 365 PowerShell
Manage SharePoint Online with Office 365 PowerShell
Manage user accounts and licenses with Office 365 PowerShell
Use Windows PowerShell to create reports in Office 365
Use Windows PowerShell to create reports in Office
365
7/18/2019 • 2 minutes to read • Edit Online
Summary: Use Office 365 PowerShell to create reports that you cannot produce in the Microsoft 365 admin
center.
There are many different reports available in the Microsoft 365 admin center. However, these reports only provide
so much information and sometimes you need more. That's when you need Office 365 PowerShell
These articles that describe how to use Office 365 PowerShell to obtain information from your Office 365 tenant:
Getting started with reporting using Office 365 PowerShell:
Office 365 PowerShell can reveal additional information that you cannot see with the Admin center
Office 365 PowerShell is great at filtering data
Office 365 PowerShell makes it easy to print or save data
Reports for user accounts and licenses:
View licenses and services with Office 365 PowerShell
View licensed and unlicensed users with Office 365 PowerShell
View account license and service details with Office 365 PowerShell
View user accounts with Office 365 PowerShell
Reports for SharePoint Online:
Manage SharePoint Online users and groups with Office 365 PowerShell
Manage SharePoint Online site groups with Office 365 PowerShell
Reports for Exchange Online:
Display Exchange Online mailbox information with Office 365 PowerShell
Display Exchange Online reports with Office 365 PowerShell
See also
Manage Office 365 with Office 365 PowerShell
Getting started with Office 365 PowerShell
Manage SharePoint Online with Office 365 PowerShell
Manage user accounts and licenses with Office 365 PowerShell
Cmdlet references for Office 365 services
5/15/2019 • 2 minutes to read • Edit Online
Summary: Find Office 365 PowerShell cmdlet reference topics for Azure Active Directory, Exchange Online,
SharePoint Online, Skype for Business Online, and Security & Compliance.
Cmdlet reference topics for the various Office 365 services provide detailed information and instructions on how
to use each cmdlet. Additionally, each Office 365 service that has PowerShell support requires different connection
instructions.
NOTE
To connect to all services at once, see Connect to all Office 365 services in a single Windows PowerShell window.
NOTE
Reporting cmdlets for other services, for example, SharePoint Online, Skype for Business Online, and Office 365 user activity
are available in Exchange Online PowerShell. For more information, see Reporting cmdlets in Exchange Online.
See also
Manage Office 365 with Office 365 PowerShell
Getting started with Office 365 PowerShell
Office 365 PowerShell community resources
5/15/2019 • 2 minutes to read • Edit Online
Summary: Get help for Office 365 PowerShell from these community venues.
Use these community forums and Wikis to get you connected to your peers and get your Office 365 PowerShell
questions answered quickly and correctly.
Visit the Office 365 Tech Community
Office 365 technical community
Exchange TechCenter community forum
Office Blogs
Manage Office 365 Wiki
See also
Manage Office 365 with Office 365 PowerShell
Getting started with Office 365 PowerShell
Manage user accounts and licenses with Office 365
PowerShell
5/15/2019 • 2 minutes to read • Edit Online
Summary: Learn how to manage user accounts and licenses with Office 365 PowerShell.
One of the primary tasks of any Office 365 administrator is managing user accounts and licenses. Although you
can accomplish some of these tasks in the Microsoft 365 admin center, other tasks are much quicker and easier
with Office 365 PowerShell. For more information, see the following topics:
View licenses and services with Office 365 PowerShell
View licensed and unlicensed users with Office 365 PowerShell
Assign licenses to user accounts with Office 365 PowerShell
View account license and service details with Office 365 PowerShell
Assign roles to user accounts with Office 365 PowerShell
Disable access to services with Office 365 PowerShell
Remove licenses from user accounts with Office 365 PowerShell
Block user accounts with Office 365 PowerShell
Delete and restore user accounts with Office 365 PowerShell
Create user accounts with Office 365 PowerShell
View user accounts with Office 365 PowerShell
Configure user account properties with Office 365 PowerShell
View licenses and services with Office 365 PowerShell
7/18/2019 • 4 minutes to read • Edit Online
Summary: Explains how to use Office 365 PowerShell to view information about the licensing plans, services,
and licenses that are available in your Office 365 organization.
Every Office 365 subscription consists of the following elements:
Licensing plans These are also known as license plans or Office 365 plans. Licensing plans define the
Office 365 services that are available to users. Your Office 365 subscription may contain multiple licensing
plans. An example licensing plan would be Office 365 Enterprise E3.
Services These are also known as service plans. Services are the Office 365 products, features, and
capabilities that are available in each licensing plan, for example, Exchange Online and Office Professional
Plus. Users can have multiple licenses assigned to them from different licensing plans that grant access to
different services.
Licenses Each licensing plan contains the number of licenses that you purchased. You assign licenses to
users so they can use the Office 365 services that are defined by the licensing plan. Every user account
requires at least one license from one licensing plan so they can log on to Office 365 and use the services.
You can use Office 365 PowerShell to view details about the available licensing plans, licenses, and services in
your Office 365 organization. For more information about the products, features, and services that are available in
different Office 365 subscriptions, see Office 365 Plan Options.
$licenses = Get-AzureADSubscribedSku
Next, display the services in a specific license plan.
$licenses[<index>].ServicePlans
<index> is an integer that specifies the row number of the license plan from the display of the
Get-AzureADSubscribedSku | Select SkuPartNumber command, minus 1.
For example, if the display of the Get-AzureADSubscribedSku | Select SkuPartNumber command is this:
SkuPartNumber
-------------
WIN10_VDA_E5
EMSPREMIUM
ENTERPRISEPREMIUM
FLOW_FREE
Then the command to display the services for the ENTERPRISEPREMIUM license plan is this:
$licenses[2].ServicePlans
NOTE
A PowerShell script is available that automates the procedures described in this topic. Specifically, the script lets you view
and disable services in your Office 365 organization, including Sway. For more information, see Disable access to Sway with
Office 365 PowerShell.
To view summary information about your current licensing plans and the available licenses for each plan, run the
following command:
Get-MsolAccountSku
ActiveUnits: Number of licenses that you've purchased for a specific licensing plan.
WarningUnits: Number of licenses in a licensing plan that you haven't renewed, and that will expire after
the 30-day grace period.
ConsumedUnits: Number of licenses that you've assigned to users from a specific licensing plan.
To view details about the Office 365 services that are available in all of your license plans, run the following
command:
The following table shows the Office 365 service plans and their friendly names for the most common services.
Your list of service plans might be different.
SWAY Sway
YAMMER_ENTERPRISE Yammer
SHAREPOINTWAC Office
For a complete list of license plans (also known as product names), their included service plans, and their
corresponding friendly names, see Product names and service plan identifiers for licensing.
To view details about the Office 365 services that are available in a specific licensing plan, use the following
syntax.
This example shows the Office 365 services that are available in the litwareinc:ENTERPRISEPACK (Office 365
Enterprise E3) licensing plan.
Summary: Explains how to use Office 365 PowerShell to view licensed and unlicensed user accounts.
User accounts in your Office 365 organization may have some, all, or none of the available licenses assigned to
them from the licensing plans that are available in your organization. You can use Office 365 PowerShell to quickly
find the licensed and unlicensed users in your organization.
To view the list of all user accounts in your organization that have been assigned any of your licensing plans
(licensed users), run the following command:
Get-MsolUser -All
To view the list of all unlicensed user accounts in your organization, run the following command:
To view the list of all licensed user accounts in your organization, run the following command:
Summary: How to use Office 365 PowerShell to assign an Office 365 license to unlicensed users.
Users can't use any Office 365 services until their account has been assigned a license from a licensing plan. You
can use Office 365 PowerShell to quickly assign licenses to unlicensed accounts.
NOTE
User accounts must be assigned a location. You can do this from the properties of a user account in the Microsoft 365
admin center or from PowerShell.
Next, get the sign-in name of the account to which you want add a license, also known as the user principal name
(UPN ).
Next, ensure that the user account has a usage location assigned.
If there is no usage location assigned, you can assign one with these commands:
Finally, specify the user sign-in name and license plan name and run these commands.
You can only assign licenses to user accounts that have the UsageLocation property set to a valid ISO 3166-1
alpha-2 country code. For example, US for the United States, and FR for France. Some Office 365 services aren't
available in certain countries. For more information, see About license restrictions.
To find accounts that don't have a UsageLocation value, run this command.
For example:
If you use the Get-MsolUser cmdlet without using the -All parameter, only the first 500 accounts are returned.
Assigning licenses to user accounts
To assign a license to a user, use the following command in Office 365 PowerShell.
This example assigns a license from the litwareinc:ENTERPRISEPACK (Office 365 Enterprise E3) licensing plan
to the unlicensed user **[email protected]**:
NOTE
You can't assign multiple licenses to a user from the same licensing plan. If you don't have enough available licenses, the
licenses are assigned to users in the order that they're returned by the Get-MsolUser cmdlet until the available licenses run
out.
This example assigns licenses from the litwareinc:ENTERPRISEPACK (Office 365 Enterprise E3) licensing plan
to all unlicensed users:
This example assigns those same licenses to unlicensed users in the Sales department in the United States:
See also
Manage user accounts and licenses with Office 365 PowerShell
Manage Office 365 with Office 365 PowerShell
Getting started with Office 365 PowerShell
View account license and service details with Office
365 PowerShell
5/15/2019 • 2 minutes to read • Edit Online
Summary: Explains how to use Office 365 PowerShell to determine the Office 365 services that have been
assigned to users.
In Office 365, licenses from licensing plans (also called SKUs or Office 365 plans) give users access to the Office
365 services that are defined for those plans. However, a user might not have access to all the services that are
available in a license that's currently assigned to them. You can use Office 365 PowerShell to view the status of
services on user accounts.
For more information about licensing plans, license, and services, see View licenses and services with Office 365
PowerShell.
Use these commands to list the services that are available in each licensing plan.
$allSKUs=Get-AzureADSubscribedSku
$licArray = @()
for($i = 0; $i -lt $allSKUs.Count; $i++)
{
$licArray += "Service Plan: " + $allSKUs[$i].SkuPartNumber
$licArray += Get-AzureADSubscribedSku -ObjectID $allSKUs[$i].ObjectID | Select -ExpandProperty ServicePlans
$licArray += ""
}
$licArray
Use these commands to list the licenses that are assigned to a user account.
Next, run this command to list the services that are available in each licensing plan, and the order in which they
are listed (the index number).
Use this command to list the licenses that are assigned to a user, and the order in which they are listed (the index
number).
NOTE
If you use the Get-MsolUser cmdlet without using the All parameter, only the first 500 accounts are returned.
This example shows the services to which the user [email protected] has access. This shows the services
that are associated with all licenses that are assigned to her account.
This example shows the services that user [email protected] has access to from the first license that's
assigned to her account (the index number is 0).
To view all the services for a user who has been assigned multiple licenses, use the following syntax:
See also
Manage user accounts and licenses with Office 365 PowerShell
Manage Office 365 with Office 365 PowerShell
Getting started with Office 365 PowerShell
Assign roles to user accounts with Office 365
PowerShell
5/30/2019 • 5 minutes to read • Edit Online
You can quickly and easily assign roles to user accounts using Office 365 PowerShell.
NOTE
Pay attention to the notes in this article. Some role names are different for Azure AD PowerShell. For example, the
"SharePoint Administrator" role in the Microsoft 365 admin center is named "SharePoint Service Administrator" for Azure AD
PowerShell.
Next, fill in the sign-in and role names and run these commands.
$userName="[email protected]"
$roleName="SharePoint Service Administrator"
$role = Get-AzureADDirectoryRole | Where {$_.displayName -eq $roleName}
if ($role -eq $null) {
$roleTemplate = Get-AzureADDirectoryRoleTemplate | Where {$_.displayName -eq $roleName}
Enable-AzureADDirectoryRole -RoleTemplateId $roleTemplate.ObjectId
$role = Get-AzureADDirectoryRole | Where {$_.displayName -eq $roleName}
}
Add-AzureADDirectoryRoleMember -ObjectId $role.ObjectId -RefObjectId (Get-AzureADUser | Where
{$_.UserPrincipalName -eq $userName}).ObjectID
To display the list of user names for a specific role, use these commands.
$roleName="<role name>"
Get-AzureADDirectoryRole | Where { $_.DisplayName -eq $roleName } | Get-AzureADDirectoryRoleMember | Ft
DisplayName
Use the Microsoft Azure Active Directory Module for Windows
PowerShell
First, connect to your Office 365 tenant using a global administrator account.
For a single role change
The most common ways of specific user account is with its display name or its email name, also known its sign-in
name user principal name (UPN ).
Display names of user accounts
If you are used to working with the display names of user accounts, determine the following:
The user account that you want to configure.
To specify the user account, you must determine its Display Name. To get a complete list accounts, use this
command:
This command lists the Display Name of your user accounts, sorted by the Display Name, one screen at a
time. You can filter the list to a smaller set by using the Where cmdlet. Here is an example:
Get-MsolUser -All | Where DisplayName -like "John*" | Sort DisplayName | Select DisplayName | More
This command lists only the user accounts for which the Display Name starts with "John".
The role you want to assign.
To display the list of available roles that you can assign to user accounts, use this command:
Once you have determined the Display Name of the account and the Name of the role, use these commands to
assign the role to the account:
Copy the commands and paste them into Notepad. For the $dispName and $roleName variables, replace the
description text with their values, remove the < and > characters, and leave the quotes. Copy the modified lines
and paste them into your Windows Azure Active Directory Module for Windows PowerShell window to run them.
Alternately, you can use the Windows PowerShell Integrated Script Environment (ISE ).
Here is an example of a completed command set:
$dispName="Scott Wallace"
$roleName="SharePoint Service Administrator"
Add-MsolRoleMember -RoleMemberEmailAddress (Get-MsolUser -All | Where DisplayName -eq
$dispName).UserPrincipalName -RoleName $roleName
This command lists the UPN of your user accounts, sorted by the UPN, one screen at a time. You can filter
the list to a smaller set by using the Where cmdlet. Here is an example:
Get-MsolUser -All | Where DisplayName -like "John*" | Sort UserPrincipalName | Select UserPrincipalName
| More
This command lists only the user accounts for which the Display Name starts with "John".
The role you want to assign.
To display the list of available roles that you can assign to user accounts, use this command:
Once you have the UPN of the account and the name of the role, use these commands to assign the role to the
account:
Copy the commands and paste them into Notepad. For the $upnName and $roleName variables, replace the
description text with their values, remove the < and > characters, and leave the quotes. Copy the modified lines
and paste them into your Windows Azure Active Directory Module for Windows PowerShell window to run them.
Alternately, you can use the Windows PowerShell ISE.
Here is an example of a completed command set:
$upnName="[email protected]"
$roleName="SharePoint Service Administrator"
Add-MsolRoleMember -RoleMemberEmailAddress $upnName -RoleName $roleName
Next, create a comma-separated value (CSV ) text file that has the display name or UPN and role name fields. You
can do this easily with Microsoft Excel.
Here is an example for display names:
DisplayName,RoleName
"Belinda Newman","Billing Administrator"
"Scott Wallace","SharePoint Service Administrator"
Next, fill in the location of the CSV file and run the resulting commands at the PowerShell command prompt.
$fileName="<path and file name of the input CSV file that has the role changes, example:
C:\admin\RoleUpdates.CSV>"
$roleChanges=Import-Csv $fileName | ForEach {Add-MsolRoleMember -RoleMemberEmailAddress (Get-MsolUser | Where
DisplayName -eq $_.DisplayName).UserPrincipalName -RoleName $_.RoleName }
UserPrincipalName,RoleName
"[email protected]","Billing Administrator"
"[email protected]","SharePoint Service Administrator"
Next, fill in the location of the CSV file and run the resulting commands at the PowerShell command prompt.
$fileName="<path and file name of the input CSV file that has the role changes, example:
C:\admin\RoleUpdates.CSV>"
$roleChanges=Import-Csv $fileName | ForEach { Add-MsolRoleMember -RoleMemberEmailAddress $_.UserPrincipalName
-RoleName $_.RoleName }
See also
Manage user accounts and licenses with Office 365 PowerShell
Manage Office 365 with Office 365 PowerShell
Getting started with Office 365 PowerShell
Disable access to services with Office 365 PowerShell
7/18/2019 • 3 minutes to read • Edit Online
Summary: Explains how to use Office 365 PowerShell to disable access to Office 365 services for users in your
organization.
When an Office 365 account is assigned a license from a licensing plan, Office 365 services are made available to
the user from that license. However, you can control the Office 365 services that the user can access. For example,
even though the license allows access to the SharePoint Online service, you can disable access to it. You can use
PowerShell to disable access to any number of services for a specific licensing plan for:
An individual account.
A group of accounts.
All accounts in your organization.
For more information, see View licenses and services with Office 365 PowerShell.
To see the before and after results of the procedures in this topic, see View account license and service details with
Office 365 PowerShell.
A PowerShell script is available that automates the procedures described in this topic. Specifically, the script lets
you view and disable services in your Office 365 organization, including Sway. For more information, see Disable
access to Sway with Office 365 PowerShell.
Disable specific Office 365 services for specific users for a specific licensing plan
To disable a specific set of Office 365 services for users for a specific licensing plan, perform the following steps:
1. Identify the undesirable services in the licensing plan by using the following syntax:
The following example creates a LicenseOptions object that disables the Office and SharePoint Online services in
the licensing plan named litwareinc:ENTERPRISEPACK (Office 365 Enterprise E3).
The following example creates a new account for Allie Bellew that assigns the license and disables the services
described in Step 1.
For more information about creating user accounts in Office 365 PowerShell, see Create user accounts with Office
365 PowerShell.
To disable the services for an existing licensed user, use the following syntax:
To disable the services described in Step 1 for all existing licensed users, specify the name of your Office 365
plan from the display of the Get-MsolAccountSku cmdlet (such as litwareinc:ENTERPRISEPACK), and
then run the following commands:
$acctSKU="<AccountSkuId>"
$AllLicensed = Get-MsolUser -All | Where {$_.isLicensed -eq $true -and $_.licenses[0].AccountSku.SkuPartNumber
-eq ($acctSKU).Substring($acctSKU.IndexOf(":")+1, $acctSKU.Length-$acctSKU.IndexOf(":")-1)}
$AllLicensed | ForEach {Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -LicenseOptions $LO}
If you use the Get-MsolUser cmdlet without using the All parameter, only the first 500 user accounts are returned.
To disable the services for a group of existing users, use either of the following methods to identify the
users:
Filter the accounts based on an existing account attribute To do this, use the following syntax:
The following example disables the services for users in the Sales department in the United States.
[email protected]
[email protected]
[email protected]
In this example, the text file is C:\My Documents\Accounts.txt.
2. Run the following command:
If you want to disable access to services for multiple licensing plans, repeat the above instructions for each
licensing plan, ensuring that:
The user accounts have been assigned the licensing plan.
The services to disable are available in the licensing plan.
To disable Office 365 services for users while you are assigning them to a licensing plan, see Disable access to
services while assigning user licenses.
See also
See the following additional topics about managing users with Office 365 PowerShell:
Delete and restore user accounts with Office 365 PowerShell
Delete and restore user accounts with Office 365 PowerShell
Block user accounts with Office 365 PowerShell
Assign licenses to user accounts with Office 365 PowerShell
Create user accounts with Office 365 PowerShell
Disable access to Sway with Office 365 PowerShell
5/15/2019 • 2 minutes to read • Edit Online
Summary Use the ManageSway.ps1 PowerShell script to disable access to Sway in your Office 365 organization.
The ManageSway.ps1 PowerShell script lets you view and disable services in your Office 365 organization,
including Sway. This script automates the procedures that are described in the following topics:
View licenses and services with Office 365 PowerShell
Disable access to services with Office 365 PowerShell
You need to download the two files that are associated with the script:
The ManageSway.ps1 script at https://go.microsoft.com/fwlink/p/?LinkId=785070
The help file for the script at https://go.microsoft.com/fwlink/p/?LinkId=785072
Disable access to services while assigning user
licenses
7/18/2019 • 4 minutes to read • Edit Online
Summary: Learn how to assign licenses to user accounts and disable specific service plans at the same time using
Office 365 PowerShell.
Office 365 subscriptions come with service plans for individual services. Office 365 administrators often need to
disable certain plans when assigning licenses to users. With the instructions in this article, you can assign an Office
365 license while disabling specific service plans using PowerShell for an individual user account or multiple user
accounts.
Get-MsolAccountSku
From the display of this command, determine which service plans you would like to disable when you assign
licenses to users.
Here is a partial list of service plans and their corresponding Office 365 services.
The following table shows the Office 365 service plans and their friendly names for the most common services.
Your list of service plans might be different.
SERVICE PLAN DESCRIPTION
SWAY Sway
YAMMER_ENTERPRISE Yammer
SHAREPOINTWAC Office
For a complete list of license plans (also known as product names), their included service plans, and their
corresponding friendly names, see Product names and service plan identifiers for licensing.
Now that you have the AccountSkuId and the service plans to disable, you can assign licenses for an individual
user or for multiple users.
For a single user
For a single user, fill in the user principal name of the user account, the AccountSkuId, and the list of service plans
to disable and remove the explanatory text and the < and > characters. Then, run the resulting commands at the
PowerShell command prompt.
Here is an example command block for the account named [email protected], for the
contoso:ENTERPRISEPACK license, and the service plans to disable are RMS_S_ENTERPRISE, SWAY,
INTUNE_O365, and YAMMER_ENTERPRISE:
$userUPN="[email protected]"
$accountSkuId="contoso:ENTERPRISEPACK"
$planList=@( "RMS_S_ENTERPRISE","SWAY","INTUNE_O365","YAMMER_ENTERPRISE" )
$licenseOptions=New-MsolLicenseOptions -AccountSkuId $accountSkuId -DisabledPlans $planList
$user=Get-MsolUser -UserPrincipalName $userUPN
$usageLocation=$user.Usagelocation
Set-MsolUserLicense -UserPrincipalName $userUpn -AddLicenses $accountSkuId -ErrorAction SilentlyContinue
Sleep -Seconds 5
Set-MsolUserLicense -UserPrincipalName $userUpn -LicenseOptions $licenseOptions -ErrorAction SilentlyContinue
Set-MsolUser -UserPrincipalName $userUpn -UsageLocation $UsageLocation
UserPrincipalName,UsageLocation
[email protected],FR
[email protected],US
[email protected],US
Next, fill in the location of the input and output CSV files, the account SKU ID, and the list of service plans to
disable, and then run the resulting commands at the PowerShell command prompt.
$inFileName="<path and file name of the input CSV file that contains the users, example:
C:\admin\Users2License.CSV>"
$outFileName="<path and file name of the output CSV file that records the results, example:
C:\admin\Users2License-Done.CSV>"
$accountSkuId="<the AccountSkuId from the Get-MsolAccountSku command>"
$planList=@( <comma-separated, double-quote enclosed list of the plans to disable> )
$users=Import-Csv $inFileName
$licenseOptions=New-MsolLicenseOptions -AccountSkuId $accountSkuId -DisabledPlans $planList
ForEach ($user in $users)
{
$user.Userprincipalname
$upn=$user.UserPrincipalName
$usageLocation=$user.UsageLocation
Set-MsolUserLicense -UserPrincipalName $upn -AddLicenses $accountSkuId -ErrorAction SilentlyContinue
sleep -Seconds 5
Set-MsolUserLicense -UserPrincipalName $upn -LicenseOptions $licenseOptions -ErrorAction SilentlyContinue
Set-MsolUser -UserPrincipalName $upn -UsageLocation $usageLocation
$users | Get-MsolUser | Select UserPrincipalName, Islicensed,Usagelocation | Export-Csv $outFileName
}
See also
Disable access to services with Office 365 PowerShell
Disable access to Sway with Office 365 PowerShell
Manage user accounts and licenses with Office 365 PowerShell
Manage Office 365 with Office 365 PowerShell
Remove licenses from user accounts with Office 365
PowerShell
7/23/2019 • 3 minutes to read • Edit Online
Summary: Explains how to use Office 365 PowerShell to remove Office 365 licenses that were previously
assigned to users.
Next, get the sign-in name of the account for which you want remove a license, also known as the user principal
name (UPN ).
Finally, specify the user sign-in and license plan names, remove the "<" and ">" characters, and run these
commands.
NOTE
You cannot use the Set-MsolUserLicense cmdlet to unassign users from canceled licenses. You must do this individually for
each user account in the Microsoft 365 admin center.
To remove licenses from a group of existing licensed users, use either of the following methods:
Filter the accounts based on an existing account attribute To do this, use the following syntax:
This example removes the litwareinc:ENTERPRISEPACK (Office 365 Enterprise E3) licenses from all accounts for
users in the Sales department in the United States.
$USSales = Get-MsolUser -All -Department "Sales" -UsageLocation "US" | where {$_.isLicensed -eq $true}
$USSales | foreach {Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -RemoveLicenses
"litwareinc:ENTERPRISEPACK"}
[email protected]
[email protected]
[email protected]
This example removes the litwareinc:ENTERPRISEPACK (Office 365 Enterprise E3) license from the user accounts
defined in the text file C:\My Documents\Accounts.txt.
To remove licenses from all existing user accounts, use the following syntax:
This example removes the litwareinc:ENTERPRISEPACK (Office 365 Enterprise E3) license from all existing licensed
user accounts.
Another way to free up a license is by deleting the user account. For more information, see Delete and restore user
accounts with Office 365 PowerShell.
See also
Manage user accounts and licenses with Office 365 PowerShell
Manage Office 365 with Office 365 PowerShell
Getting started with Office 365 PowerShell
Summary: Explains how to use Office 365 PowerShell to block and unblock access to Office 365 accounts.
Blocking access to an Office 365 account prevents anyone from using the account to sign in and access the
services and data in your Office 365 organization. You can use Office 365 PowerShell to block access to individual
and multiple user accounts.
NOTE
The -ObjectID parameter in the Set-AzureAD cmdlet accepts either the account sign-in name, also known as the User
Principal Name, or the account's object ID.
To display the user account UPN based on the user's display name, use the following commands:
$userName="<display name>"
Write-Host (Get-AzureADUser | where {$_.DisplayName -eq $userName}).UserPrincipalName
This example displays the user account UPN for the user named Caleb Sills.
$userName="Caleb Sills"
Write-Host (Get-AzureADUser | where {$_.DisplayName -eq $userName}).UserPrincipalName
To block an account based on the user's display name, use the following commands:
$userName="<display name>"
Set-AzureADUser -ObjectID (Get-AzureADUser | where {$_.DisplayName -eq $userName}).UserPrincipalName -
AccountEnabled $false
At any time, you can check the blocked status of a user account with the following command:
[email protected]
[email protected]
[email protected]
In the following commands, the example text file is C:\My Documents\Accounts.txt. Replace this with the path and
file name of your text file.
To block access to the accounts listed in the text file, run the following command:
To unblock the accounts listed in the text file, run the following command:
At any time, you can check the blocked status of a user account with the following command:
Get-MsolUser -UserPrincipalName <sign-in name of user account> | Select DisplayName,BlockCredential
[email protected]
[email protected]
[email protected]
In the following commands, the example text file is C:\My Documents\Accounts.txt. Replace this with the path and
file name of your text file.
To block access to the accounts listed in the text file, run the following command:
To unblock the accounts listed in the text file, run the following command:
See also
Manage user accounts and licenses with Office 365 PowerShell
Manage Office 365 with Office 365 PowerShell
Getting started with Office 365 PowerShell
Delete user accounts with Office 365 PowerShell
5/15/2019 • 2 minutes to read • Edit Online
Summary: Learn how to use Office 365 PowerShell to delete Office 365 user accounts.
You can use Office 365 PowerShell to delete a user account.
NOTE
The -ObjectID parameter in the Remove-AzureAD cmdlet accepts either the account's sign-in name, also known as the
User Principal Name, or the account's object ID.
To display the account name based on the user's name, use the following commands:
$userName="<User name>"
Write-Host (Get-AzureADUser | where {$_.DisplayName -eq $userName}).UserPrincipalName
This example displays the account name for the user named Caleb Sills.
$userName="Caleb Sills"
Write-Host (Get-AzureADUser | where {$_.DisplayName -eq $userName}).UserPrincipalName
To remove an account based on the user's display name, use the following commands:
$userName="<display name>"
Remove-AzureADUser -ObjectID (Get-AzureADUser | where {$_.DisplayName -eq $userName}).UserPrincipalName
To restore a deleted user account within the 30-day grace period, use the following syntax:
Notes:
To see the list of deleted users that can be restored, run the following command:
If the user account's original user principal name is used by another account, use the
NewUserPrincipalName parameter instead of UserPrincipalName to specify a different user principal
name when you restore the user account.
See also
Manage user accounts and licenses with Office 365 PowerShell
Manage Office 365 with Office 365 PowerShell
Getting started with Office 365 PowerShell
Create user accounts with Office 365 PowerShell
5/15/2019 • 3 minutes to read • Edit Online
Summary: Learn how to use Office 365 PowerShell to create user accounts in Office 365.
You can use Office 365 PowerShell to efficiently create user accounts, especially multiple user accounts. When you
create user accounts in Office 365 PowerShell, certain account properties are always required. Other properties
aren't required to create the account, but are otherwise important. These properties are described in the following
table:
FirstName No
LastName No
This example creates an account for the United States user named Caleb Sills:
New-MsolUser -DisplayName <display name> -FirstName <first name> -LastName <last name> -UserPrincipalName
<sign-in name> -UsageLocation <ISO 3166-1 alpha-2 country code> -LicenseAssignment <licensing plan name> [-
Password <Password>]
Get-MsolAccountSku
This example creates an account for the United States user named Caleb Sills, and assigns a license from the
contoso:ENTERPRISEPACK ( Office 365 Enterprise E3 ) licensing plan.
New-MsolUser -DisplayName "Caleb Sills" -FirstName Caleb -LastName Sills -UserPrincipalName
[email protected] -UsageLocation US -LicenseAssignment contoso:ENTERPRISEPACK
UserPrincipalName,FirstName,LastName,DisplayName,UsageLocation,AccountSkuId
[email protected],Claude,Loiselle,Claude Loiselle,US,contoso:ENTERPRISEPACK
[email protected],Lynne,Baxter,Lynne Baxter,US,contoso:ENTERPRISEPACK
[email protected],Shawn,Melendez,Shawn Melendez,US,contoso:ENTERPRISEPACK
NOTE
The column names and their order in the first row of the CSV file are arbitrary, but make sure the data in the rest of the file
matches the order of the column names, and use the column names for the parameter values in the Office 365 PowerShell
command.
Import-Csv -Path <Input CSV File Path and Name> | foreach {New-MsolUser -DisplayName $_.DisplayName -FirstName
$_.FirstName -LastName $_.LastName -UserPrincipalName $_.UserPrincipalName -UsageLocation $_.UsageLocation -
LicenseAssignment $_.AccountSkuId [-Password $_.Password]} | Export-Csv -Path <Output CSV File Path and Name>
This example creates the user accounts from the file named C:\My Documents\NewAccounts.csv, and logs the
results in the file named C:\My Documents\NewAccountResults.csv
3. Review the output file to see the results. We didn't specify passwords, so the random passwords that Office 365
generated are visible in the output file.
See also
Manage user accounts and licenses with Office 365 PowerShell
Manage Office 365 with Office 365 PowerShell
Getting started with Office 365 PowerShell
View user accounts with Office 365 PowerShell
7/18/2019 • 8 minutes to read • Edit Online
Summary: View your user accounts in various ways with Office 365 PowerShell.
Although you can use the Microsoft 365 admin center to view the accounts for your Office 365 tenant, you can
also use Office 365 PowerShell and do some things that the admin center cannot.
Get-AzureADUser
Here is an example:
As another example, you can check the enabled status of a specific user account with the following command:
This command instructs Azure Active Directory PowerShell for Graph to:
Get all of the information on the user accounts ( Get-AzureADUser ) and send it to the next command ( | ).
Find all of the user accounts that have an unspecified usage location ( Where-Object {$_.UsageLocation -
eq $Null} ). Inside the braces, the command instructs Office 365 PowerShell to only find the set of
accounts in which the UsageLocation user account property ( $_.UsageLocation ) is not specified ( -eq
$Null ).
The UsageLocation property is only one of many properties associated with a user account. To see all of the
properties for user accounts, use the Select-Object cmdlet and the wildcard character (*) to display them all for a
specific user account. Here is an example:
For example, from this list, City is the name of a user account property. This means you can use the following
command to list all of the user accounts for users living in London:
Get-MsolUser
The Get-MsolUser cmdlet also has a set of parameters to filter the set of user accounts displayed. For example,
for the list of unlicensed users (users who've been added to Office 365 but haven't yet been licensed to use any of
the services), run this command.
Get-MsolUser -UnlicensedUsersOnly
For more information about additional parameters to filter the display the set of user accounts displayed, see Get-
MsolUser.
View a specific account
To display a specific user account, fill in the sign-in name of the user account of the user account, also known as the
user principal name (UPN ), remove the "<" and ">" characters, and run this command:
The UsageLocation property is only one of many properties associated with a user account. To see all of the
properties for user accounts, use the Select-Object cmdlet and the wildcard character (*) to display them all for a
specific user account. Here is an example:
For example, from this list, City is the name of a user account property. This means you can use the following
command to list all of the user accounts for users living in London:
TIP
The syntax for the Where-Object cmdlet shown in these examples is Where-Object {$_. [user account property name]
[comparison operator] [value] }. [comparison operator] is -eq for equals, -ne for not equals, -lt for less than, -gt for greater
than, and others. [value] is typically a string (a sequence of letters, numbers, and other characters), a numerical value, or
$Null for unspecified. See Where-Object for more information.
You can check the blocked status of a user account with the following command:
The Select-Object cmdlet lets you pick and choose the properties you want a command to display. To see all of
the properties for user accounts, use the wildcard character (*) to display them all for a specific user account. Here
is an example:
To be more selective about the list of accounts to display, you can also use the Where-Object cmdlet. Here is an
example command that displays only those user accounts that have an unspecified usage location:
See also
Manage user accounts and licenses with Office 365 PowerShell
Manage Office 365 with Office 365 PowerShell
Getting started with Office 365 PowerShell
Configure user account properties with Office 365
PowerShell
7/18/2019 • 6 minutes to read • Edit Online
Summary: Use Office 365 PowerShell to configure properties of individual or multiple user accounts in your
Office 365 tenant.
Although you can use the Microsoft 365 admin center to configure properties for the user accounts of your Office
365 tenant, you can also use Office 365 PowerShell and do some things that the admin center cannot.
$userName="<Display name>"
Write-Host (Get-AzureADUser | where {$_.DisplayName -eq $userName}).UserPrincipalName
This example displays the User Principal Name for the user account with the display name of Caleb Sills.
$userName="Caleb Sills"
Write-Host (Get-AzureADUser | where {$_.DisplayName -eq $userName}).UserPrincipalName
By using a $upn variable, you can make changes to individual accounts based on their display name. Here is an
example of setting Belinda Newman's usage location to France, but specifying her display name rather than her
User Principal Name:
$userName="Belinda Newman"
$upn=(Get-AzureADUser | where {$_.DisplayName -eq $userName}).UserPrincipalName
Set-AzureADUser -ObjectID $upn -UsageLocation "FR"
$userName="<Display name>"
Write-Host (Get-MsolUser | where {$_.DisplayName -eq $userName}).UserPrincipalName
This example displays the User Principal Name for the user named Caleb Sills.
$userName="Caleb Sills"
Write-Host (Get-MsolUser | where {$_.DisplayName -eq $userName}).UserPrincipalName
By using a $upn variable, you can make changes to individual accounts based on their display name. Here is an
example of setting Belinda Newman's usage location to France, but specifying her display name rather than her
User Principal Name:
$userName="<display name>"
$upn=(Get-MsolUser | where {$_.DisplayName -eq $userName}).UserPrincipalName
Set-MsolUser -UserPrincipalName $upn -UsageLocation "FR"
See also
Manage user accounts and licenses with Office 365 PowerShell
Manage Office 365 with Office 365 PowerShell
Getting started with Office 365 PowerShell
Manage Office 365 Groups with PowerShell
5/15/2019 • 5 minutes to read • Edit Online
$groupAlias = "<GroupAlias>"
$userAlias = "<UserAlias>"
Once the cmdlet is executed, users can go to Outlook or Outlook on the web to send as the group, by adding the
group email address to the From field.
In order to associate a description to each classification you can use the settings attribute ClassificationDescriptions
to define.
$setting["ClassificationDescriptions"] ="Classification:Description,Classification:Description"
After you run the above Azure Active Directory cmdlet to set your classification, run the Set-UnifiedGroup cmdlet if
you want to set the classification for a specific group.
Check out Using PowerShell with Exchange Online and Connect to Exchange Online PowerShell for more details
on using Exchange Online PowerShell.
Once these settings are enabled, the group owner will be able to choose a classification from the drop down menu
in Outlook on the Web and Outlook, and save it from the Edit group page.
Hide Office 365 Groups from GAL
You can specify whether a Office 365 group appears in the global address list (GAL ) and other lists in your
organization. For example, if you have a legal department group that you don't want to show up in the address list,
you can stop that group from appearing in GAL. Run the Set-Unified Group cmdlet to hide the group from address
list like this:
Along with MailTip, you can also set MailTipTranslations, which specifies additional languages for the MailTip.
Suppose you want to have the Spanish translation, then run the following command:
Set-UnifiedGroup -Identity "MailaTip Group" -MailTip "This group has a MailTip" -MailTipTranslations
"@{Add="ES:Esta caja no se supervisa."
Change the default setting of Office 365 Groups for Outlook to Public
or Private
Office 365 Groups in Outlook are created as Private by default. If your organization wants Office 365 Groups to be
created as Public by default (or back to Private), use this PowerShell cmdlet syntax:
Set-OrganizationConfig -DefaultGroupAccessType Public
To set to Private:
Set-OrganizationConfig -DefaultGroupAccessType Private
Get-UnifiedGroup Use this cmdlet to look up existing Office 365 Groups, and to
view properties of the group object
New-UnifiedGroup Create a new Office 365 group. This cmdlet provides a minimal
set of parameters, for setting values for extended properties
use Set-UnifiedGroup after creating the new group
Related topics
Upgrade distribution lists to Office 365 Groups
Manage who can create Office 365 Groups
Manage guest access to Office 365 Groups
Change static group membership to dynamic in
Manage SharePoint Online with Office 365
PowerShell
5/15/2019 • 2 minutes to read • Edit Online
Summary: Use Office 365 PowerShell to manage SharePoint Online users, groups, and site groups.
One of the primary tasks of any SharePoint Online administrator is managing sites, site groups, and users.
Although you can accomplish some of these tasks in the Microsoft 365 admin center, other tasks are much quicker
and easier in Office 365 PowerShell. For more information, see the following topics:
Connect to SharePoint Online PowerShell
Create SharePoint Online sites and add users with Office 365 PowerShell
Manage SharePoint Online users and groups with Office 365 PowerShell
Manage SharePoint Online site groups with Office 365 PowerShell
See also
Manage Office 365 with Office 365 PowerShell
Getting started with Office 365 PowerShell
Create SharePoint Online sites and add users with
Office 365 PowerShell
5/15/2019 • 4 minutes to read • Edit Online
Summary: Use Office 365 PowerShell to create new SharePoint Online sites, and then add users and groups to
those sites.
When you use Office 365 PowerShell to create SharePoint Online sites and add users, you can quickly and
repeatedly perform tasks much faster than you can in the Office 356 admin center. You can also perform tasks that
are not possible to perform in the Office 356 admin center.
Owner,StorageQuota,Url,ResourceQuota,Template,TimeZoneID,Name
[email protected],100,https://tenant.sharepoint.com/sites/TeamSite01,25,EHS#1,10,Contoso Team Site
[email protected],100,https://tenant.sharepoint.com/sites/Blog01,25,BLOG#0,10,Contoso Blog
[email protected],150,https://tenant.sharepoint.com/sites/Project01,25,PROJECTSITE#0,10,Project
Alpha
[email protected],150,https://tenant.sharepoint.com/sites/Community01,25,COMMUNITY#0,10,Community
Site
Where tenant is the name of your tenant, and owner is the user name of the user on your tenant to whom you
want to grant the role of primary site collection administrator.
(You can press Ctrl+H when you use Notepad to bulk replace faster.)
2. Save the file on your desktop as SiteCollections.csv.
TIP
Before you use this or any other .csv or Windows PowerShell script file, it is good practice to make sure that there are no
extraneous or nonprinting characters. Open the file in Word, and in the ribbon, click the paragraph icon to show nonprinting
characters. There should be no extraneous nonprinting characters. For example, there should be no paragraph marks beyond
the final one at the end of the file.
4. Note the new site collections in the list. You should see the following site collections: contosotest,
TeamSite01, Blog01, and Project01
That’s it. You’ve created multiple site collections using the .csv file you created and a single Windows PowerShell
cmdlet. You’re now ready to create and assign users to these sites.
Site,Group,PermissionLevels
https://tenant.sharepoint.com/sites/contosotest,Contoso Project Leads,Full Control
https://tenant.sharepoint.com/sites/contosotest,Contoso Auditors,View Only
https://tenant.sharepoint.com/sites/contosotest,Contoso Designers,Design
https://tenant.sharepoint.com/sites/TeamSite01,XT1000 Team Leads,Full Control
https://tenant.sharepoint.com/sites/TeamSite01,XT1000 Advisors,Edit
https://tenant.sharepoint.com/sites/Blog01,Contoso Blog Designers,Design
https://tenant.sharepoint.com/sites/Blog01,Contoso Blog Editors,Edit
https://tenant.sharepoint.com/sites/Project01,Project Alpha Approvers,Full Control
Group,LoginName,Site
Contoso Project Leads,[email protected],https://tenant.sharepoint.com/sites/contosotest
Contoso Auditors,[email protected],https://tenant.sharepoint.com/sites/contosotest
Contoso Designers,[email protected],https://tenant.sharepoint.com/sites/contosotest
XT1000 Team Leads,[email protected],https://tenant.sharepoint.com/sites/TeamSite01
XT1000 Advisors,[email protected],https://tenant.sharepoint.com/sites/TeamSite01
Contoso Blog Designers,[email protected],https://tenant.sharepoint.com/sites/Blog01
Contoso Blog Editors,[email protected],https://tenant.sharepoint.com/sites/Blog01
Project Alpha Approvers,[email protected],https://tenant.sharepoint.com/sites/Project01
Where tenant equals your tenant name, and username equals the user name of an existing user.
4. Save the file to your desktop as Users.csv.
5. Open a new instance of Notepad, and paste the following text block into it:
Where MyAlias equals the user name of the user that is currently logged on.
6. Save the file to your desktop as UsersAndGroups.ps1. This is a simple Windows PowerShell script.
You’re now ready to run the UsersAndGroup.ps1 script to add users and groups to multiple site collections.
Run UsersAndGroups.ps1 script
1. Return to the SharePoint Online Management Shell.
2. At the Windows PowerShell prompt, type or copy and paste the following line, and press Enter:
Set-ExecutionPolicy Bypass
c:\users\MyAlias\desktop\UsersAndGroups.ps1
See also
Connect to SharePoint Online PowerShell
Manage SharePoint Online site groups Office 365 PowerShell
Manage Office 365 with Office 365 PowerShell
Getting started with Office 365 PowerShell
Manage SharePoint Online users and groups with
Office 365 PowerShell
5/15/2019 • 7 minutes to read • Edit Online
Summary: Use Office 365 PowerShell to manage SharePoint Online users, groups, and sites.
If you are a SharePoint Online administrator who works with large lists of user accounts or groups and wants an
easier way to manage them, you can use Office 365 PowerShell.
Get-SPOSite
To use these commands, replace replace everything within the quotes, including the < and > characters, with the
correct names.
For example, this set of commands adds Opal Castillo (user name opalc) the list of Site Collection Administrators
on the ContosoTest site collection in the contoso1 tenancy:
$tenant = "contoso1"
$site = "contosotest"
$user = "opalc"
Set-SPOUser -Site https://$tenant.sharepoint.com/sites/$site -LoginName $user@$tenant.onmicrosoft.com -
IsSiteCollectionAdmin $true
You can copy and paste these commands into Notepad, change the variable values for $tenant, $site, and $user to
actual values from your environment, and then paste this into your SharePoint Online Management Shell window
to run them.
For example, let’s add Glen Rife (user name glenr) to the Auditors group on the ContosoTest site collection in the
contoso1 tenancy:
$tenant = "contoso1"
$site = "contosotest"
$user = "glenr"
$group = "Auditors"
Add-SPOUser -Group $group -LoginName $user@$tenant.onmicrosoft.com -Site
https://$tenant.sharepoint.com/sites/$site
Group properties, such as permission levels, can be updated later by using the Set-SPOSiteGroup cmdlet.
For example, let’s add the Auditors group with View Only permissions to the Contoso Test site collection in the
contoso1 tenancy:
$tenant = "contoso1"
$site = "Contoso Test"
$group = "Auditors"
$level = "View Only"
New-SPOSiteGroup -Group $group -PermissionLevels $level -Site https://$tenant.sharepoint.com/sites/$site
For example, let’s remove Bobby Overby from the site collection Auditors group in the Contoso Test site collection
in the contoso1 tenancy:
$tenant = "contoso1"
$site = "contosotest"
$user = "bobbyo"
$group = "Auditors"
Remove-SPOUser -LoginName $user@$tenant.onmicrosoft.com -Site https://$tenant.sharepoint.com/sites/$site -
Group $group
Suppose we wanted to remove Bobby from all the groups he is currently in. Here is how we would do that:
$tenant = "contoso1"
$user = "bobbyo"
Get-SPOSite | ForEach {Get-SPOSiteGroup –Site $_.Url} | ForEach {Remove-SPOUser -LoginName
$user@$tenant.onmicrosoft.com -Site &_.Url}
WARNING
This is just an example. You should not run this command unless you really have to remove a user from every group, for
example if the user leaves the company.
Site,Group,PermissionLevels
Item:
https://tenant.sharepoint.com/sites/site,group,level
Site,Group,PermissionLevels
https://contoso1.sharepoint.com/sites/contosotest,Contoso Project Leads,Full Control
https://contoso1.sharepoint.com/sites/contosotest,Contoso Auditors,View Only
https://contoso1.sharepoint.com/sites/contosotest,Contoso Designers,Design
https://contoso1.sharepoint.com/sites/TeamSite01,XT1000 Team Leads,Full Control
https://contoso1.sharepoint.com/sites/TeamSite01,XT1000 Advisors,Edit
https://contoso1.sharepoint.com/sites/Blog01,Contoso Blog Designers,Design
https://contoso1.sharepoint.com/sites/Blog01,Contoso Blog Editors,Edit
https://contoso1.sharepoint.com/sites/Project01,Project Alpha Approvers,Full Control
The second CSV file will add one or more users to one or more groups and will have this structure:
Header:
Group,LoginName,Site
Item:
group,login,https://tenant.sharepoint.com/sites/site
Group,LoginName,Site
Contoso Project Leads,[email protected],https://contoso1.sharepoint.com/sites/contosotest
Contoso Auditors,[email protected],https://contoso1.sharepoint.com/sites/contosotest
Contoso Designers,[email protected],https://contoso1.sharepoint.com/sites/contosotest
XT1000 Team Leads,[email protected],https://contoso1.sharepoint.com/sites/TeamSite01
XT1000 Advisors,[email protected],https://contoso1.sharepoint.com/sites/TeamSite01
Contoso Blog Designers,[email protected],https://contoso1.sharepoint.com/sites/Blog01
Contoso Blog Editors,[email protected],https://contoso1.sharepoint.com/sites/Blog01
Project Alpha Approvers,[email protected],https://contoso1.sharepoint.com/sites/Project01
For the next step, you must have the two CSV files saved to your drive. Here are example commands that use both
CSV files and to add permissions and group membership:
Import-Csv C:\O365Admin\GroupsAndPermissions.csv | ForEach {New-SPOSiteGroup -Group $_.Group -PermissionLevels
$_.PermissionLevels -Site $_.Site}
Import-Csv C:\O365Admin\Users.csv | ForEach {Add-SPOUser -Group $_.Group –LoginName $_.LoginName -Site
$_.Site}
The script imports the CSV file contents and uses the values in the columns to populate the parameters of the
New-SPOSiteGroup and Add-SPOUser commands. In our example, we are saving this to theO365Admin folder
on drive C, but you can save it wherever you want.
Now, let’s remove a bunch of people for several groups in different sites using the same CSV file. Here is an
example command:
This will grab the data for these three sites and write them to a text file on your local drive. Note that the parameter
–Append will add new content to an existing file.
For example, let's run a report on the ContosoTest, TeamSite01, and Project01 sites for the Contoso1 tenant:
$tenant = "contoso1"
$site = "contosotest"
Get-SPOUser -Site https://$tenant.sharepoint.com/sites/$site | Format-Table -Wrap -AutoSize | Out-File
c:\UsersReport.txt -Force -Width 360 -Append
$site = "TeamSite01"
Get-SPOUser -Site https://$tenant.sharepoint.com/sites/$site |Format-Table -Wrap -AutoSize | Out-File
c:\UsersReport.txt -Force -Width 360 -Append
$site = "Project01"
Get-SPOUser -Site https://$tenant.sharepoint.com/sites/$site | Format-Table -Wrap -AutoSize | Out-File
c:\UsersReport.txt -Force -Width 360 -Append
Note that we had to change only the $site variable. The $tenant variable keeps its value through all three runs of
the command.
However, what if you wanted to do this for every site? You can do this without having to type all those websites by
using this command:
Get-SPOSite | ForEach {Get-SPOUser –Site $_.Url} | Format-Table -Wrap -AutoSize | Out-File c:\UsersReport.txt
-Force -Width 360 -Append
This report is fairly simple, and you can add more code to create more specific reports or reports that include
more detailed information. But this should give you an idea of how to use the SharePoint Online Management
Shell to manage users in the SharePoint Online environment.
See also
Connect to SharePoint Online PowerShell
Manage SharePoint Online with Office 365 PowerShell
Manage Office 365 with Office 365 PowerShell
Getting started with Office 365 PowerShell
Manage SharePoint Online site groups with Office
365 PowerShell
5/15/2019 • 2 minutes to read • Edit Online
Summary: Use Office 365 PowerShell to manage SharePoint Online site groups.
Although you can use the Microsoft 365 admin center, you can also use Office 365 PowerShell to manage your
SharePoint Online site groups.
1. From the Microsoft 365 admin center, click Resources > Sites, and then click the URL of the site.
2. In the site collection dialog box, click Go to this site.
3. On the site page, click the Settings icon (located in the upper right-hand corner of the page) and then click Site
settings:
4. On the Site Settings page, click Sites permissions under Users and Permissions.
And then repeat the process for the next site you want to look at.
To get a list of the groups with Office 365 PowerShell, you would use the following command set:
$siteURL = "https://litwareinc.sharepoint.com/sites/finance"
$x = Get-SPOSiteGroup -Site $siteURL
foreach ($y in $x)
{
Write-Host $y.Title -ForegroundColor "Yellow"
Get-SPOSiteGroup -Site $siteURL -Group $y.Title | Select-Object -ExpandProperty Users
Write-Host
}
There are two ways to run this command set in the SharePoint Online Management Shell command prompt:
Copy the commands into Notepad (or another text editor), modify the value of the $siteURL variable, select
the commands, and then paste them into the SharePoint Online Management Shell command prompt. When
you do, PowerShell will stop at a >> prompt. Press Enter to execute the foreach command.
Copy the commands into Notepad (or another text editor), modify the value of the $siteURL variable, and then
save this text file with a name and the .ps1 extension in a suitable folder. Next, run the script from the
SharePoint Online Management Shell command prompt by specifying its path and file name. Here is an
example command:
C:\Scripts\SiteGroupsAndUsers.ps1
These are all the groups that have been created for the site https://litwareinc.sharepoint.com/sites/finance , and
all the users assigned to those groups. The group names are in yellow to help you separate group names from
their members.
As another example, here is a command set that lists the groups, and all the group memberships, for all of your
SharePoint Online sites.
$x = Get-SPOSite
foreach ($y in $x)
{
Write-Host $y.Url -ForegroundColor "Yellow"
$z = Get-SPOSiteGroup -Site $y.Url
foreach ($a in $z)
{
$b = Get-SPOSiteGroup -Site $y.Url -Group $a.Title
Write-Host $b.Title -ForegroundColor "Cyan"
$b | Select-Object -ExpandProperty Users
Write-Host
}
}
See also
Connect to SharePoint Online PowerShell
Create SharePoint Online sites and add users with Office 365 PowerShell
Manage SharePoint Online users and groups with Office 365 PowerShell
Manage Office 365 with Office 365 PowerShell
Getting started with Office 365 PowerShell
Manage Exchange Online with Office 365 PowerShell
5/15/2019 • 2 minutes to read • Edit Online
Summary: Use Office 365 PowerShell to manage Microsoft Exchange Online, including displaying mailbox
configuration and advanced reporting.
One of the primary tasks of any Microsoft Exchange Online administrator is managing mailboxes and getting
reports on them. Although you can accomplish some of these tasks in the Microsoft 365 admin center, other tasks
are much quicker and easier in Office 365 PowerShell. For more information, see the following topics:
Display Exchange Online mailbox information with Office 365 PowerShell
Display Exchange Online reports with Office 365 PowerShell
Determine which cmdlets are available to Exchange Online administrators with Office 365 PowerShell
See also
Manage Office 365 with Office 365 PowerShell
Getting started with Office 365 PowerShell
Use PowerShell for email migration to Office 365
5/15/2019 • 2 minutes to read • Edit Online
Summary: Learn how to migrate email to Office 365 using Windows PowerShell.
When administrators first set up Office 365, many of them migrate email from existing systems. You can also do
this by using the Office 365 administration user interface. You can also use Windows PowerShell to migrate email.
See also
Manage Office 365 with Office 365 PowerShell
Getting started with Office 365 PowerShell
Manage SharePoint Online with Office 365 PowerShell
Use Windows PowerShell to create reports in Office 365
Advantages of using Windows PowerShell to manage Office 365
Windows PowerShell in Office 365 technical reference
Office 365 Licensing and Windows PowerShell
Use PowerShell to perform a cutover migration to
Office 365
5/15/2019 • 9 minutes to read • Edit Online
Summary: Learn how to use Windows PowerShell to perform a cutover migration to Office 365.
You can migrate the contents of user mailboxes from a source email system to Office 365 all at once by using a
cutover migration. This article walks you through the tasks for an email cutover migration by using Exchange
Online PowerShell.
By reviewing the topic, What you need to know about a cutover email migration to Office 365, you can get an
overview of the migration process. When you're comfortable with the contents of that article, use this one to begin
migrating mailboxes from one email system to another.
NOTE
You can also use the Exchange admin center to perform a cutover migration. See Perform a cutover migration of email to
Office 365.
Migration steps
Step 1: Prepare for a cutover migration
Add your on-premises Exchange organization as an accepted domain of your Office 365
organization. The migration service uses the SMTP address of your on-premises mailboxes to create the
Microsoft Online Services user ID and email address for the new Office 365 mailboxes. Migration will fail if
your Exchange domain isn't an accepted domain or the primary domain of your Office 365 organization.
For more information, seeVerify your domain in Office 365.
Configure Outlook Anywhere on your on-premises Exchange server. The email migration service
uses RPC over HTTP, or Outlook Anywhere, to connect to your on-premises Exchange server. For
information about how to set up Outlook Anywhere for Exchange 2010, Exchange 2007, and Exchange
2003, see the following:
Exchange 2010: Enable Outlook Anywhere
Exchange 2007: How to Enable Outlook Anywhere
Exchange 2003: Deployment Scenarios for RPC over HTTP
How to Configure Outlook Anywhere with Exchange 2003
IMPORTANT
Your Outlook Anywhere configuration must be configured with a certificate issued by a trusted certification
authority (CA). It can't be configured with a self-signed certificate. For more information, see How to
Configure SSL for Outlook Anywhere.
Verify that you can connect to your Exchange organization using Outlook Anywhere. Try one of
these methods to test your connection settings:
Use Microsoft Outlook from outside your corporate network to connect to your on-premises
Exchange mailbox.
Use the Microsoft Exchange Remote Connectivity Analyzer to test your connection settings. Use the
Outlook Anywhere (RPC over HTTP ) or Outlook Autodiscover tests.
Run the following commands in Exchange Online PowerShell.
$Credentials = Get-Credential
Assign an on-premises user account the necessary permissions to access mailboxes in your
Exchange organization. The on-premises user account that you use to connect to your on-premises
Exchange organization (also called the migration administrator) must have the necessary permissions to
access the on-premises mailboxes that you want to migrate to Office 365. This user account is used to
create a migration endpoint to your on-premises organization.
The following list shows the administrative privileges required to migrate mailboxes using a cutover
migration. There are three possible options.
The migration administrator must be a member of the Domain Admins group in Active Directory in
the on-premises organization.
Or
The migration administrator must be assigned the FullAccess permission for each on-premises
mailbox.
Or
The migration administrator must be assigned the Receive As permission on the on-premises
mailbox database that stores the user mailboxes.
Disable Unified Messaging. If the on-premises mailboxes you're migrating are enabled for Unified
Messaging (UM ), you have to disable UM on the mailboxes before you migrate them. You can then enable
UM on the mailboxes after the migration is complete.
Security Groups and Delegates The email migration service cannot detect whether on-premises Active
Directory groups are security groups or not, so it cannot provision any migrated groups as security groups
in Office 365. If you want to have security groups in your Office 365 tenant, you must first provision an
empty mail-enabled security group in your Office 365 tenant before starting the cutover migration.
Additionally, this migration method only moves mailboxes, mail users, mail contacts, and mail-enabled
groups. If any other Active Directory object, such as user that is not migrated to Office 365, is assigned as a
manager or delegate to an object being migrated, they must be removed from the object before you
migrate.
Step 2: Create a migration endpoint
To migrate email successfully, Office 365 needs to connect and communicate with the source email system. To do
this, Office 365 uses a migration endpoint. To create an Outlook Anywhere migration endpoint for cutover
migration, first connect to Exchange Online.
For a full list of migration commands, see Move and migration cmdlets.
Run the following commands in Exchange Online PowerShell:
$Credentials = Get-Credential
The example uses the Test-MigrationServerAvailability cmdlet to obtain and test the connection settings to the on-
premises Exchange server, and then uses those connection settings to create the migration endpoint called
"CutoverEndpoint".
NOTE
The New-MigrationEndpoint cmdlet can be used to specify a database for the service to use by using the -
TargetDatabase option. Otherwise a database is randomly assigned from the Active Directory Federation Services (AD FS)
2.0 site where the management mailbox is located.
Verify it worked
In Exchange Online PowerShell, run the following command to display information about the "CutoverEndpoint"
migration endpoint:
This example also creates a migration batch called "CutoverBatch" and uses the migration endpoint that was
created in the previous step. Because the AutoStart parameter isn't included, the migration batch has to be
manually started on the migration dashboard or by using Start-MigrationBatch cmdlet. As previously stated,
only one cutover migration batch can exist at a time.
Verify it worked
To verify that you've successfully created a migration batch for a cutover migration, run the following command in
Exchange Online PowerShell to display information about the new migration batch:
Get-MigrationBatch | Format-List
Verify it worked
If a migration batch is successfully started, its status on the migration dashboard is specified as Syncing. To verify
that you've successfully started a migration batch using Exchange Online PowerShell, run the following command:
NOTE
In Exchange 2007, Exchange 2010, and Exchange 2013 you should also set
Set-ClientAccessServer AutodiscoverInternalConnectionURI to Null .
Office 365 uses a CNAME record to implement the Autodiscover service for Outlook and mobile clients.
The Autodiscover CNAME record must contain the following information:
Alias: autodiscover
Target: autodiscover.outlook.com
For more information, see Create DNS records for Office 365 when you manage your DNS records.
Decommission on-premises Exchange servers. After you've verified that all email is being routed
directly to the Office 365 mailboxes, and you no longer need to maintain your on-premises email
organization or don't plan on implementing a single sign-on (SSO ) solution, you can uninstall Exchange
from your servers and remove your on-premises Exchange organization.
For more information, see the following:
Modify or Remove Exchange 2010
How to Remove an Exchange 2007 Organization
How to Uninstall Exchange Server 2003
Use PowerShell to perform an IMAP migration to
Office 365
5/15/2019 • 9 minutes to read • Edit Online
Summary: Learn how to use Windows PowerShell to perform an IMAP migration to Office 365.
As part of the process of deploying Office 365, you can choose to migrate the contents of user mailboxes from an
Internet Mail Access Protocol (IMAP ) email service to Office 365. This article walks you through the tasks for an
email IMAP migration by using Exchange Online PowerShell.
NOTE
You can also use the Exchange admin center to perform an IMAP migration. See Migrate your IMAP mailboxes to Office 365.
Migration steps
Step 1: Prepare for an IMAP migration
If you have a domain for you IMAP organization, add it as an accepted domain of your Office 365
organization. If you want to use the same domain you already own for your Office 365 mailboxes, you first
have to add it as an accepted domain to Office 365. After you have added it, you can create your users in
Office 365. For more information, seeVerify your domain in Office 365.
Add each user to Office 365 so that they have an Office 365 mailbox. For instructions, seeAdd users
to Office 365 for business.
Obtain the FQDN of the IMAP server. You need to provide the fully qualified domain name (FQDN )
(also called the full computer name) of the IMAP server that you will migrate mailbox data from when you
create an IMAP migration endpoint. Use an IMAP client or the PING command to verify that you can use
the FQDN to communicate with the IMAP server over the Internet.
Configure the firewall to allow IMAP connections. You might have to open ports in the firewall of the
organization that hosts the IMAP server so network traffic originating from the Microsoft datacenter during
the migration is allowed to enter the organization that hosts the IMAP server. For a list of IP addresses used
by Microsoft datacenters, see Exchange Online URLs and IP Address Ranges.
Assign the administrator account permissions to access mailboxes in your IMAP organization. If
you use administrator credentials in the CSV file, the account that you use must have the necessary
permissions to access the on-premises mailboxes. The permissions required to access user mailboxes is
determined by the particular IMAP server.
To use the Exchange Online PowerShell cmdlets, you need to sign in and import the cmdlets into your
local Windows PowerShell session. See Connect to Exchange Online using remote PowerShell for
instructions.
For a full list of migration commands, see Move and migration cmdlets.
Verify that you can connect to your IMAP server. Run the following command in Exchange Online
PowerShell to test the connection settings to your IMAP server.
Test-MigrationServerAvailability -IMAP -RemoteServer <FQDN of IMAP server> -Port <143 or 993> -Security
<None, Ssl, or Tls>
For the value of the Port parameter, it's typical to use 143 for unencrypted or Transport Layer Security (TLS )
connections and to use 993 for SSL connections.
Step 2: Create a CSV file for an IMAP migration batch
Identify the group of users whose mailboxes you want to migrate in an IMAP migration batch. Each row in the
CSV file contains information necessary to connect to a mailbox in the IMAP messaging system.
Here are the required attributes for each user:
EmailAddress specifies the user ID for the user's Office 365 mailbox.
UserName specifies the logon name for the account to use to access the mailbox on the IMAP server.
Password specifies the password for the account in the UserName column.
Here's an example of the format for the CSV file. In this example, three mailboxes are migrated:
EmailAddress,UserName,Password
[email protected],terry.adams,1091990
[email protected],ann.beebe,2111991
[email protected],paul.cannon,3281986
For the UserName attribute, in addition to the user name, you can use the credentials of an account that has been
assigned the necessary permissions to access mailboxes on the IMAP server, the following are some of the specific
formats used for some of the IMAP servers:
Microsoft Exchange:
If you're migrating email from the IMAP implementation for Microsoft Exchange, use the format
Domain/Admin_UserName/User_UserName for the UserName attribute in the CSV file. Let's say you're
migrating email from Exchange for Terry Adams, Ann Beebe, and Paul Cannon. You have a mail administrator
account, where the user name is mailadmin and the password is **P@ssw0rd**. Here's what your CSV file would
look like:
EmailAddress,UserName,Password
[email protected],contoso-students/mailadmin/terry.adams,P@ssw0rd
[email protected],contoso-students/mailadmin/ann.beebe,P@ssw0rd
[email protected],contoso-students/mailadmin/paul.cannon,P@ssw0rd
Dovecot:
For IMAP servers that support Simple Authentication and Security Layer (SASL ), such as a Dovecot IMAP server,
use the format User_UserName*Admin_UserName, where the asterisk ( * ) is a configurable separator character.
Let's say you're migrating those same users' email from a Dovecot IMAP server using the administrator
credentials mailadmin and **P@ssw0rd**. Here's what your CSV file would look like:
EmailAddress,UserName,Password
[email protected],terry.adams*mailadmin,P@ssw0rd
[email protected],ann.beebe*mailadmin,P@ssw0rd
[email protected],paul.cannon*mailadmin,P@ssw0rd
Mirapoint:
If you're migrating email from Mirapoint Message Server, use the format **#user@domain#Admin_UserName#**
for the administrator credentials. To migrate email from Mirapoint using the administrator credentials mailadmin
and **P@ssw0rd**, your CSV file would look like this:
EmailAddress,UserName,Password
[email protected],#[email protected]#mailadmin#,P@ssw0rd
[email protected],#[email protected]#mailadmin#,P@ssw0rd
[email protected],#[email protected]#mailadmin#,P@ssw0rd
Courier IMAP:
Some source email systems, such as Courier IMAP, don't support using mailbox admin credentials to migrate
mailboxes to Office 365. Instead, you can set up your source email system to use virtual shared folders. By using
virtual shared folders, you can use the mailbox admin credentials to access user mailboxes on the source email
system. For more information about how to configure virtual shared folders for Courier IMAP, see Shared Folders.
To migrate mailboxes after you set up virtual shared folders on your source email system, you have to include the
optional attribute UserRoot in the migration file. This attribute specifies the location of each user's mailbox in the
virtual shared folder structure on the source email system. For example, the path to Terry's mailbox is
/users/terry.adams.
Here's an example of a CSV file that contains the UserRoot attribute:
EmailAddress,UserName,Password,UserRoot
[email protected],mailadmin,P@ssw0rd,/users/terry.adams
[email protected],mailadmin,P@ssw0rd,/users/ann.beebe
[email protected],mailadmin,P@ssw0rd,/users/paul.cannon
New-MigrationEndpoint -IMAP -Name IMAPEndpoint -RemoteServer imap.contoso.com -Port 993 -Security Ssl
You can also add parameters to specify concurrent migrations, concurrent incremental migrations, and the port to
use. The following Exchange Online PowerShell command creates an IMAP migration endpoint called
"IMAPEndpoint" that supports 50 concurrent migrations and up to 25 concurrent incremental synchronizations. It
also configures the endpoint to use port 143 for TLS encryption.
New-MigrationEndpoint -IMAP -Name IMAPEndpoint -RemoteServer imap.contoso.com -Port 143 -Security Tls -
MaxConcurrentMigrations
50 -MaxConcurrentIncrementalSyncs 25
Verify it worked
Run the Get-MigrationBatch cmdlet to display information about the "IMAPBatch1":
You can also verify that the batch has started by running the following command:
Get-MigrationBatch IMAPBatch1"
The command will return either the migration batch with a status of Removing, or it will return an error stating
that migration batch couldn't be found, verifying that the batch was deleted.
For more information about the Get-MigrationBatch cmdlet, seeGet-MigrationBatch.
See also
IMAP Migration Troubleshooter
Use PowerShell to perform a staged migration to
Office 365
5/15/2019 • 11 minutes to read • Edit Online
Summary: Learn how to use Windows PowerShell to perform a staged migration to Office 365.
You can migrate the contents of user mailboxes from a source email system to Office 365 over time using a staged
migration.
This article walks you through the tasks involved with for a staged email migration using Exchange Online
PowerShell. The topic, What you need to know about a staged email migration to Office 365, gives you an
overview of the migration process. When you're comfortable with the contents of that article, use this one to begin
migrating mailboxes from one email system to another.
NOTE
You can also use the Exchange admin center to perform staged migration. See Perform a staged migration of email to Office
365.
Migration steps
Step 1: Prepare for a staged migration
Before you migrate mailboxes to Office 365 by using a staged migration, there are a few changes you must make
to your Exchange environment.
Configure Outlook Anywhere on your on-premises Exchange Server The email migration service uses
Outlook Anywhere (also known as RPC over HTTP ), to connect to your on-premises Exchange Server. For
information about how to set up Outlook Anywhere for Exchange Server 2007, and Exchange 2003, see the
following:
Exchange 2007: How to Enable Outlook Anywhere
How to configure Outlook Anywhere with Exchange 2003
IMPORTANT
You must use a certificate issued by a trusted certification authority (CA) with your Outlook Anywhere configuration. Outlook
Anywhere can't be configured with a self-signed certificate. For more information, see How to configure SSL for Outlook
Anywhere.
Optional: Verify that you can connect to your Exchange organization using Outlook Anywhere Try one of
the following methods to test your connection settings.
Use Outlook from outside your corporate network to connect to your on-premises Exchange mailbox.
Use the Microsoft Exchange Remote Connectivity Analyzer to test your connection settings. Use the
Outlook Anywhere (RPC over HTTP ) or Outlook Autodiscover tests.
Run the following commands in Exchange Online PowerShell:
$Credentials = Get-Credential
Set permissions The on-premises user account that you use to connect to your on-premises Exchange
organization (also called the migration administrator) must have the necessary permissions to access the on-
premises mailboxes that you want to migrate to Office 365. This user account is used when you connect to your
email system by creating a migration endpoint later in this procedure (Step 3: Create a migration endpoint ).
To migrate the mailboxes, the admin must have one of the following permission sets:
Be a member of the Domain Admins group in Active Directory in the on-premises organization.
or
Be assigned the FullAccess permission for each on-premises mailbox and the WriteProperty permission
to modify the TargetAddress property on the on-premises user accounts.
or
Be assigned the Receive As permission on the on-premises mailbox database that stores user mailboxes
and the WriteProperty permission to modify the TargetAddress property on the on-premises user
accounts.
For instructions about how to set these permissions, see Assign permissions to migrate mailboxes to Office 365.
Disable Unified Messaging (UM ) If UM is turned on for the on-premises mailboxes you're migrating, turn off
UM before migration. Turn on UM for the mailboxes after migration is complete. For how -to steps, seedisable
unified messaging.
Use directory synchronization to create new users in Office 365. You use directory synchronization to create
all the on-premises users in your Office 365 organization.
You need to license the users after they're created. You have 30 days to add licenses after the users are created. For
steps to add licenses, see Step 8: Complete post-migration tasks.
You can use either the Microsoft Azure Active Directory Synchronization Tool or the Microsoft Azure Active
Directory Sync Services (AAD Sync) to synchronize and create your on-premises users in Office 365. After
mailboxes are migrated to Office 365, you manage user accounts in your on-premises organization, and they're
synchronized with your Office 365 organization. For more information, seeDirectory Integration .
Step 2: Create a CSV file for a staged migration batch
After you identify the users whose on-premises mailboxes you want to migrate to Office 365, you use a comma
separated value (CSV ) file to create a migration batch. Each row in the CSV file—used by Office 365 to run the
migration—contains information about an on-premises mailbox.
NOTE
There isn't a limit for the number of mailboxes that you can migrate to Office 365 using a staged migration. The CSV file for a
migration batch can contain a maximum of 2,000 rows. To migrate more than 2,000 mailboxes, create additional CSV files
and use each file to create a new migration batch.
Supported attributes
The CSV file for a staged migration supports the following three attributes. Each row in the CSV file corresponds
to a mailbox and must contain a value for each of these attributes.
EmailAddress,Password,ForceChangePassword
[email protected],Pa$$w0rd,False
[email protected],Pa$$w0rd,False
[email protected],Pa$$w0rd,False
Each row under the header row represents one user and supplies the information that will be used to migrate the
user's mailbox. The attribute values in each row must be in the same order as the attribute names in the header
row.
Use any text editor, or an application like Excel , to create the CSV file. Save the file as a .csv or .txt file.
NOTE
If the CSV file contains non-ASCII or special characters, save the CSV file with UTF-8 or other Unicode encoding. Depending
on the application, saving the CSV file with UTF-8 or other Unicode encoding can be easier when the system locale of the
computer matches the language used in the CSV file.
$Credentials = Get-Credential
NOTE
The New-MigrationEndpoint cmdlet can be used to specify a database for the service to use by using the -
TargetDatabase option. Otherwise a database is randomly assigned from the Active Directory Federation Services (AD FS)
2.0 site where the management mailbox is located.
Verify it worked
In Exchange Online PowerShell, run the following command to display information about the "StagedEndpoint"
migration endpoint:
This example also creates a migration batch called "StagedBatch1" and uses the migration endpoint that was
created in the previous step. Because the AutoStart parameter isn't included, the migration batch has to be
manually started on the migration dashboard or by using Start-MigrationBatch cmdlet. As previously stated,
only one cutover migration batch can exist at a time.
Verify it worked
Run the following command in Exchange Online PowerShell to display information about the "StagedBatch1":
You can also verify that the batch has started by running the following command:
Get-MigrationBatch StagedBatch1
The command will return either the migration batch with a status of Removing, or it will return an error stating
that migration batch couldn't be found, verifying that the batch was deleted.
For more information about the Get-MigrationBatch cmdlet, seeGet-MigrationBatch.
Step7: Assign licenses to Office 365 users
Activate Office 365 user accounts for the migrated accounts by assigning licenses. If you don't assign a license, the
mailbox is disabled when the grace period (30 days) ends. To assign a license in the Microsoft 365 admin center,
see Assign or unassign licenses for Office 365 for business.
Step 8: Complete post-migration tasks
Create an Autodiscover DNS record so users can easily get to their mailboxes. After all on-premises
mailboxes are migrated to Office 365, you can configure an Autodiscover DNS record for your Office 365
organization to enable users to easily connect to their new Office 365 mailboxes with Outlook and mobile
clients. This new Autodiscover DNS record has to use the same namespace that you're using for your Office
365 organization. For example, if your cloud-based namespace is cloud.contoso.com, the Autodiscover DNS
record you need to create is autodiscover.cloud.contoso.com.
Office 365 uses a CNAME record to implement the Autodiscover service for Outlook and mobile clients.
The Autodiscover CNAME record must contain the following information:
Alias: autodiscover
Target: autodiscover.outlook.com
For more information, see Create DNS records for Office 365 when you manage your DNS records.
Decommission on-premises Exchange servers. After you've verified that all email is being routed
directly to the Office 365 mailboxes, and you no longer need to maintain your on-premises email
organization or don't plan on implementing an SSO solution, you can uninstall Exchange from your servers
and remove your on-premises Exchange organization.
For more information, see the following:
Modify or Remove Exchange 2010
How to Remove an Exchange 2007 Organization
How to Uninstall Exchange Server 2003
Manage Office 365 with Windows PowerShell for
Delegated Access Permissions (DAP) partners
7/18/2019 • 2 minutes to read • Edit Online
Summary: Syndication and Cloud Solution Provider (CSP ) partners can use Windows PowerShell to manage
Office 365 customer tenants.
Delegated Access Permission (DAP ) partners are Syndication and Cloud Solution Providers (CSP ) Partners. They
are frequently network or telecom providers to other companies. They bundle Office 365 subscriptions into their
service offerings to their customers. When they sell an Office 365 subscription, they are automatically granted
Administer On Behalf Of (AOBO ) permissions to the customer tenancies so they can administer and report on the
customer tenancies. At best, this is difficult and time consuming to do in the Microsoft 365 admin center. It is much
easier to do administrative tasks like listing all the customer TenantIds and their domains or identifying all users in
a customer tenancy and what licenses they are assigned by using Windows PowerShell for Office 365. In some
cases, it is possible to do these administrative tasks only in Windows PowerShell for Office 365. Here are samples
of scenarios that Syndication and CSP partners most frequently use to administer their customer tenancies:
Manage Office 365 tenants with Windows PowerShell for Delegated Access Permissions (DAP ) partners
Add a domain to a client tenancy with Windows PowerShell for Delegated Access Permission (DAP )
partners
Connect to Exchange Online tenants with remote Windows PowerShell for Delegated Access Permissions
(DAP ) partners
Retrieve customer tenant reporting data with Windows PowerShell for Delegated Access Permissions (DAP )
partners
Manage Office 365 tenants with Windows PowerShell
for Delegated Access Permissions (DAP) partners
7/18/2019 • 3 minutes to read • Edit Online
Summary: Use Windows PowerShell for Office 365 to manage your customer tenancies.
Windows PowerShell allows Syndication and Cloud Solution Provider (CSP ) partners to easily administer and
report on customer tenancy settings that are not available in the Microsoft 365 admin center. Note that Administer
on Behalf Of (AOBO ) permissions are required for the partner administrator account to connect to its customer
tenancies.
Delegated Access Permission (DAP ) partners are Syndication and Cloud Solution Providers (CSP ) Partners. They
are frequently network or telecom providers to other companies. They bundle Office 365 subscriptions into their
service offerings to their customers. When they sell an Office 365 subscription, they are automatically granted
Administer On Behalf Of (AOBO ) permissions to the customer tenancies so they can administer and report on the
customer tenancies.
NOTE
If you have more than 500 tenants, scope the cmdlet syntax with either -All or -MaxResultsParameter. This applies to other
cmdlets that can give a large output, such as Get-MsolUser.
To list all customer tenant Ids that you have access to, run this command.
If you have registered additional domains, this will return all domains associated with the customer TenantId.
Get a mapping of all tenants and registered domains
The previous Windows PowerShell for Office 365 commands showed you how to retrieve either tenant IDs or
domains but not both at the same time, and with no clear mapping between them all. This command generates a
listing of all your customer tenant IDs and their domains.
Get-MsolUser -TenantId <customer TenantId value> -UserPrincipalName <user principal name value>
where:
UsageLocation: The value for this is the two-letter ISO country/region code of the user. The
country/region codes can be looked up at theISO Online Browsing Platform. For example, the code for the
United States is US, and the code for Brazil is BR.
LicenseAssignment: The value for this uses this format: syndication-account:<PROVISIONING_ID> . For
example, if you are assigning customer tenant users O365_Business_Premium licenses, the
LicenseAssignment value looks like this: syndication-account:O365_Business_Premium. You will find
the PROVISIONING_IDs in the Syndication Partner Portal that you have access to as a Syndication or CSP
partner.
Import the CSV file and create the users
After you have your CSV file created, run this command to create user accounts with non-expiring passwords that
the user must change at first sign-in and that assigns the license you specify. Be sure to substitute the correct CSV
file name.
Import-Csv .\FILENAME.CSV | foreach {New-MsolUser -UserPrincipalName $_.UserPrincipalName -DisplayName
$_.DisplayName -FirstName $_.FirstName -LastName $_.LastName -Password $_.Password -UsageLocation
$_.UsageLocation -LicenseAssignment $_.LicenseAssignment -ForceChangePassword:$true -
PasswordNeverExpires:$true -TenantId $_.TenantId}
See also
Help for partners
Add a domain to a client tenancy with Windows
PowerShell for Delegated Access Permission (DAP)
partners
7/24/2019 • 3 minutes to read • Edit Online
Summary: Use Windows PowerShell for Office 365 to add an alternate domain name to an existing customer
tenant.
You can create and associate new domains with your customer's tenancy with Windows PowerShell for Office 365
faster than using the Microsoft 365 admin center.
Delegated Access Permission (DAP ) partners are Syndication and Cloud Solution Providers (CSP ) Partners. They
are frequently network or telecom providers to other companies. They bundle Office 365 subscriptions into their
service offerings to their customers. When they sell an Office 365 subscription, they are automatically granted
Administer On Behalf Of (AOBO ) permissions to the customer tenancies so they can administer and report on the
customer tenancies.
Create domains
Your customers will likely ask you to create additional domains to associate with their tenancy because they don't
want the default .onmicrosoft.com domain to be the primary one that represents their corporate identities to the
world. This procedure walks you through creating a new domain associated with your customer's tenancy.
NOTE
To perform some of these operations, the partner administrator account you sign in with must be set to Full administration
for the Assign administrative access to companies you support setting found in the details of the admin account in the
Microsoft 365 admin center. For more information on managing partner administrator roles, seePartners: Offer delegated
administration.
Text: MS=ms########
Ttl: 3600
NOTE
You will need this text to create the TXT record in the publicly registered DNS zone. Be sure to copy and save it.
text=MS=ms########
This command won't return any output, so to confirm that this worked, run this command.
Get-MsolDomain -TenantId <customer TenantId> -DomainName <FQDN of new domain>
See also
Help for partners
Connect to Exchange Online tenants with remote
Windows PowerShell for Delegated Access
Permissions (DAP) partners
5/15/2019 • 4 minutes to read • Edit Online
Summary: Use remote PowerShell to connect to Exchange Online by using the DelegatedOrg value.
IMPORTANT
The procedures in this topic are only for Delegated Access Permission (DAP) partners. If you aren't a DAP partner, don't use
the procedures in this topic.
DAP partners are Syndication and Cloud Solution Providers (CSP ) partners. They are frequently network or
telecom providers to other companies. They bundle subscriptions into their service offerings to their customers.
They own a partner tenancy that is automatically granted Administer On Behalf Of (AOBO ) permissions to their
Office 365 customer tenancies so they can administer and report on all of their customer tenancies.
DAP partners can use Exchange Online PowerShell to manage customer Exchange Online settings and get Office
365 reports from the command line. You use Windows PowerShell on your local computer to create a remote
PowerShell session to Exchange Online. It's a simple three-step process where you enter your credentials, provide
the required connection settings, and then import the Exchange Online cmdlets into your local Windows
PowerShell session so that you can use them.
NOTE
DAP partners can't use the procedures in Connect to Exchange Online PowerShell using multi-factor authentication to
connect to their customer tenant organizations in Exchange Online PowerShell. MFA and the Exchange Online Remote
PowerShell Module don't work with delegated authentication.
To require all PowerShell scripts that you download from the internet are signed by a trusted publisher, run
the following command in an elevated Windows PowerShell window (a Windows PowerShell window you
open by selecting Run as administrator):
Set-ExecutionPolicy RemoteSigned
You need to configure this setting only once on your computer, not every time you connect.
For information about keyboard shortcuts that might apply to the procedures in this topic, see Keyboard
shortcuts in the Exchange admin center.
$UserCredential = Get-Credential
In the Windows PowerShell Credential Request dialog box, enter your DAP administrator user name
and password, and then click OK.
2. Replace <customer tenant domain name> with the name of the tenant domain that you want to connect to,
and run the following command:
The key step in this command is specifying which customer to access for the reporting information. You do
this in the ConnectionURI parameter, where you provide the FQDN of the initial domain name as the value
for ?DelegatedOrg= . This value indicates the correct Exchange Online PowerShell endpoint to connect to.
Remote PowerShell must connect to Office 365 reporting in the context of a specific customer each time a
report is run. After you connect to Exchange Online PowerShell, all subsequent commands are run in the
context of the customer, which gives you access to all of the available reports for the customer.
3. Run the following command.
Import-PSSession $Session
NOTE
There's a limit of three simultaneous sessions that can run under one account. Be sure to disconnect the remote PowerShell
session when you're finished. If you close the Windows PowerShell window without disconnecting the session, you can use
up all the remote PowerShell sessions available to you, and you'll need to wait for the sessions to expire. To disconnect the
remote PowerShell session, run the following command:
Remove-PSSession $Session
Summary: Use remote Windows PowerShell for Microsoft Exchange Online to retrieve reports from individual
customer tenants.
Syndication and Cloud Solution Provider (CSP ) partners can access the data that makes up customer tenant
reports directly via remoteWindows PowerShell for Exchange Online PowerShell. This lets partners collect and
save the reporting data and then perform other operations on it. After you open a remote connection, retrieving
reporting data about a customer tenancy is identical to running any cmdlet against a customer tenancy.
In this article, you use remoteWindows PowerShell for Exchange Online to connect to a single customer tenancy
and retrieve a report. By default, Windows PowerShell does not support aggregating reporting data from multiple
customer tenancies. The reports you retrieve with this procedure are only for the DelegatedOrg that you connect
to.
There are many other reporting cmdlets available for Exchange Online, Lync Online, and SharePoint Online as well
as others for message tracing that you can use. To find out more about the available reporting cmdlets and the
Office 365 Reporting web service, see the topics in the following section.
See also
Office 365 Reporting web service
Reporting cmdlets in Exchange Online
Help for partners
Manage Skype for Business Online with Office 365
PowerShell
7/18/2019 • 2 minutes to read • Edit Online
Summary: Use Office 365 PowerShell to manage Skype for Business Online policies, per-user policies, and
meeting settings.
One of the primary tasks of any Skype for Business Online administrator is managing policies. Although you can
accomplish some of these tasks in the Microsoft 365 admin center, other tasks are much quicker and easier in
Office 365 PowerShell.
Import-Module SkypeOnlineConnector
$userCredential = Get-Credential
$sfbSession = New-CsOnlineSession -Credential $userCredential
Import-PSSession $sfbSession
2. In the Windows PowerShell Credential Request dialog box, type your Skype for Business Online
administrator account name and password, and then click OK.
Import-Module SkypeOnlineConnector
$sfbSession = New-CsOnlineSession
Import-PSSession $sfbSession
2. When prompted by the New-CsOnlineSession command, enter your Skype for Business Online
administrator account name.
3. In the Sign in to your account dialog box, type your Skype for Business Online administrator password,
and then click Sign in.
4. Follow the instructions in the Sign in to your account dialog box to provide additional authentication
information, such as a verification code, and then click Verify.
For more information, see the following topics:
Manage Skype for Business Online policies with Office 365 PowerShell
Assign per-user Skype for Business Online policies with Office 365 PowerShell
See also
Manage Office 365 with Office 365 PowerShell
Getting started with Office 365 PowerShell
Skype for Business PowerShell cmdlet references
Manage Skype for Business Online policies with
Office 365 PowerShell
8/12/2019 • 3 minutes to read • Edit Online
Summary: Use Office 365 PowerShell to manage your Skype for Business Online user account properties with
policies.
To manage many properties of user account for Skype for Business Online, you must specify them as properties of
policies with Office 365 PowerShell.
Import-Module SkypeOnlineConnector
$userCredential = Get-Credential
$sfbSession = New-CsOnlineSession -Credential $userCredential
Import-PSSession $sfbSession
When prompted, enter your Skype for Business Online administrator account name and password.
Identity : Tag:FederationAndPICDefault
Description :
EnableFederationAccess : True
EnableXmppAccess : False
EnablePublicCloudAccess : True
EnablePublicCloudAudioVideoAccess : True
EnableOutsideAccess : True
In this example, the values within this policy determine what a use can or cannot do when it comes to
communicating with federated users. For example, the EnableOutsideAccess property must be set to True for a
user to be able to communicate with people outside the organization. Note that this property does not appear in
the Microsoft 365 admin center. Instead, the property is automatically set to True or False based on the other
selections that you make. The other two properties of interest are:
EnableFederationAccess indicates whether the user can communicate with people from federated
domains.
EnablePublicCloudAccess indicates whether the user can communicate with Windows Live users.
Therefore, you don't directly change federation-related properties on user accounts (for example, Set-CsUser -
EnableFederationAccess $True). Instead, you assign an account an external access policy that has the desired
property values preconfigured. If we want a user to be able to communicate with federated users and with
Windows Live users, that user account must be assigned a policy that allows those types of communication.
If you want to know whether or not someone can communicate with users from outside the organization, you have
to:
Determine which external access policy has been assigned to that user.
Determine which capabilities are or are not allowed by that policy.
For example, you can do that by using this command:
This command finds the policy assigned to the user, then finds the capabilities enabled or disabled within that
policy.
To manage Skype for Business Online policies with PowerShell, see the cmdlets for:
Client policy
Conferencing policy
Mobile policy
Online Voicemail policy
Voice Routing policy
NOTE
A Skype for Business Online dial plan is a policy in every respect except the name. The name "dial plan" was chosen instead of,
say, "dialing policy" in order to provide backward compatibility with Office Communications Server and with Exchange.
For example, to look at all the voice policies available for your use, run this command:
Get-CsVoicePolicy
NOTE
That returns a list of all the voice policies available to you. Keep in mind, however, that not all policies can be assigned to all
users. This is due to various restrictions involving licensing and geographic location. (The so-called "usage location.") If you
want to know the external access policies and the conferencing policies that can be assigned to a particular user, use
commands similar to these:
The ApplicableTo parameter limits the returned data to policies that can be assigned to the specified user (for
example, Alex Darrow ). Depending on licensing and usage location restrictions, that might represent a subset of all
the available policies.
In some cases, properties of policies are not used with Office 365, while others can only be managed by Microsoft
support personnel.
With Skype for Business Online, users must be managed by a policy of some kind. If a valid policy-related
property is blank, that means that the user in question is being managed by a global policy, which is a policy that is
automatically applied to a user unless he or she is specifically assigned a per-user policy. Because we don't see a
client policy listed for a user account, it is managed by the global policy. You can determine the global client policy
with this command:
See also
Manage Skype for Business Online with Office 365 PowerShell
Manage Office 365 with Office 365 PowerShell
Getting started with Office 365 PowerShell
Assign per-user Skype for Business Online policies
with Office 365 PowerShell
5/15/2019 • 4 minutes to read • Edit Online
Summary: Use Office 365 PowerShell to assign per-user communication settings with Skype for Business Online
policies.
Using Office 365 PowerShell is an efficient way to assign per-user communication settings with Skype for
Business Online policies.
Import-Module LyncOnlineConnector
$userCredential = Get-Credential
$sfbSession = New-CsOnlineSession -Credential $userCredential
Import-PSSession $sfbSession
When prompted, enter your Skype for Business Online administrator account name and password.
NOTE
You can't create a custom policy all our own. That's because Skype for Business Online does not allow you to create custom
policies. Instead, you must assign one of the policies that were created specifically for Office 365. Those pre-created policies
include: 4 different client policies, 224 different conferencing policies, 5 different dial plans, 5 different external access policies,
1 hosted voicemail policy, and 4 different voice policies.
So how do you determine which external access policy to assign Alex? The following command returns all the
external access policies where EnableFederationAccess is set to True and EnablePublicCloudAccess is set to False:
What the command does is return all the policies that meet two criteria: the EnableFederationAccess property is
set to True, and the EnablePublicCloudAccess policy is set to False. In turn, that command returns one policy that
meets our criteria (FederationOnly). Here is an example:
Identity : Tag:FederationOnly
Description :
EnableFederationAccess : True
EnableXmppAccess : False
EnablePublicCloudAccess : False
EnablePublicCloudAudioVideoAccess : False
EnableOutsideAccess : True
NOTE
The policy Identity says Tag:FederationOnly. As it turns out, the Tag: prefix is a carryover from the early pre-release work
done on Microsoft Lync 2013. When it comes to assigning policies to users, you should delete the Tag: prefix and use just the
policy name: FederationOnly.
Now that you know which policy to assign to Alex, we can assign that policy by using the Grant-
CsExternalAccessPolicy cmdlet. Here is an example:
Assigning a policy is pretty simple: you simply specify the Identity of the user and the name of the policy to be
assigned.
And when it comes to policies and policy assignments, you're not limited to working with user accounts one a time.
For example, suppose you need a list of all the users who are allowed to communicate with federated partners and
with Windows Live users. We already know that those users have been assigned the external user access policy
FederationAndPICDefault. Because we know that, you can display a list of all those users by running one simple
command. Here is the command:
In other words, show us all the users where the ExternalAccessPolicy property is set to FederationAndPICDefault.
(And, in order to limit the amount of information that appears onscreen, use the Select-Object cmdlet to display
show us only each user's display name.)
To configure all our user accounts to use that same policy, use this command:
This command uses Get-CsOnlineUser to return a collection of all the users who have been enabled for Lync, then
sends all that information to Grant-CsExternalAccessPolicy, which assigns the FederationAndPICDefault policy to
each and every user in the collection.
As an additional example, suppose you've previously assigned Alex the FederationAndPICDefault policy and now
you've changed your mind and would like him to be managed by the global external access policy. You can't
explicitly assign the global policy to anyone. It is only used if no other per-user policy is assigned. Therefore, if we
want Alex to be managed by the global policy, you need to unassign any per-user policy previously assigned to
him. Here is an example command:
See also
Manage Skype for Business Online with Office 365 PowerShell
Manage Office 365 with Office 365 PowerShell
Getting started with Office 365 PowerShell