다음을 통해 공유


OFFICE 365: USER MANAGEMENT USING POWERSHELL

In this article we will discuss some of the useful PowerShell Commands for managing Users in Office 365 (O365)

If you want to follow along then the prerequisite for this article are:

  • Having a O365 Account created
  • PowerShell for Office 365 configured

If the above prerequisites does not meet then I would recommend you to read one of my earlier article “Office 365: How to Configure PowerShell for O365” to get to know the steps of installing prerequisites.

  • Login to O365 Portal

https://howtodowithsharepoint.files.wordpress.com/2015/12/117.png?w=800

  • Click on the Admin Center Tile

https://howtodowithsharepoint.files.wordpress.com/2015/12/29.png?w=800

  • Click on “Active Users” navigation link under “Users” in the left navigation

Currently we can see only one Active User “Prashant Bansal”.

Since this is a free trail account so we cannot have more than one user here, but if you go for a paid plan then you can get multiple users as well.

https://howtodowithsharepoint.files.wordpress.com/2015/12/34.png?w=800

Now in the following sections we will be looking into some of the useful operation and corresponding PowerShell commands regarding User Management

Export All Users

Command

Get-MsolUser

Usage

This command returns all the active users present in your O365 Account

Output

https://howtodowithsharepoint.files.wordpress.com/2015/12/44.png?w=943&h=314

https://howtodowithsharepoint.files.wordpress.com/2015/12/54.png?w=800

Export All Users with matching filter

Let’s see some of the properties of the User Profile available for every User added. Based on these properties we can export filtered set of Users. Lets’ check for the User properties first –

  • Select the User
  • Click Edit on the Profile Card on the right

https://howtodowithsharepoint.files.wordpress.com/2015/12/64.png?w=800

  • Expand Additional Details
  • I have updated the User properties and now going to filter the Users based on “Job Title” property

https://howtodowithsharepoint.files.wordpress.com/2015/12/74.png?w=800

Command

Get-MsolUser -Title “SharePoint Technical Consultant”

Usage

This command export all the Users where “Job Title = SharePoint Technical Consultant”

Output

https://howtodowithsharepoint.files.wordpress.com/2015/12/84.png?w=800

 Export All Users with matching filter and selected properties

Command

Get-MsolUser -Title “SharePoint Technical Consultant” | Select DisplayName

Usage

This command export only “Display Names” for all the Users where “Job Title = SharePoint Technical Consultant”

Output:

https://howtodowithsharepoint.files.wordpress.com/2015/12/94.png?w=800

Export All Users with matching filter and selected properties to a file

Command

Get-MsolUser -Title “SharePoint Technical Consultant” | Select DisplayName > “C:\SharePoint-Online-User-Data.txt”

Usage

This command export only “Display Names” for all the Users where “Job Title = SharePoint Technical Consultant” to a Text File at the specified path

Output

https://howtodowithsharepoint.files.wordpress.com/2015/12/104.png?w=800

Create New Users

Command

New-MsolUser -UserPrincipalName “spdev002@spdevs001.onmicrosoft.com” -DisplayName “Prashant Bansal New User” -LastName “New User” -LicenseAssignment “spdevs001:DEVELOPERPACK” -UsageLocation “IN”

Usage

This command Adds a new User to the O365 Account specified by parameter “UserPrincipalName” and sets its basic properties like “Display Name, Last Name” and so on. It also assigns the license to the user specified by the parameter “LicenseAssignment”.

It is important to note that passing location information as specified by the parameter “UsageLocation” is mandatory as this is used by Microsoft for tracking the location where the service is consumed. This valid value for this parameter could be a two letter country code like for India it should be “IN”

If I execute this command I would get the following error since a free trail O365 account grant me a Single User license only.

If I am having proper license supporting multiple Users, this command would add a new User to my O365 Account.

Output

https://howtodowithsharepoint.files.wordpress.com/2015/12/118.png?w=800

Modify Existing Users

Command

Set-MsolUser -UserPrincipalName “spdev001@spdevs001.onmicrosoft.com” -LastName “Mohan Bansal” -DisplayName “Prashant Mohan Bansal”

Usage

Using this command we can modify an existing User in our O365 Account specified by parameter “UserPrincipalName” and providing its properties like “Display Name, Last Name” and so on that needs to be updated.

Output

https://howtodowithsharepoint.files.wordpress.com/2015/12/124.png?w=800

Once update is performed it might take a couple of minutes to take effect in O365 Account.

User Properties before update command executed:

https://howtodowithsharepoint.files.wordpress.com/2015/12/134.png?w=800

User Properties after update command executed:

https://howtodowithsharepoint.files.wordpress.com/2015/12/144.png?w=800

https://howtodowithsharepoint.files.wordpress.com/2015/12/154.png?w=800

That all for this article on User Management using PowerShell for O365.

All of the above Operations can be automated and using same PowerShell Development paradigms as we followed for On Premise SharePoint Implementations.