Provision And Manage User Accounts In Office 365 Using PowerShell And UI

Office 365 provides different methods of licensing models and the pricing for the service is offered on a per user basis. If we want the Office 365 and SharePoint services to be available to the new users, we can add the users from the Office 365 Admin Center and provide them access to the required SharePoint sites from the SharePoint Permissions Management page.

In this article, we will see how to perform the below actions in Office 365 from UI as well as using PowerShell.

  • Add new users
  • Remove the users
  • Edit User properties

Perform User actions using PowerShell

In order to use PowerShell to connect to Office 365, we will have to install a couple of PowerShell Modules in the local machine. You can see how to set up the environment here.

Add users to Office 365

Once the PowerShell module is installed, spin up ‘Azure Active Directory Module for Windows PowerShell’.



Run the below commands to connect to Office 365 subscription.

$UserCredential = Get-Credential
Connect-MsolService -Credential $UserCredential




Now, You can add a new user to Office 365 subscription using the below script.

New-MsolUser -DisplayName <DisplayName> -FirstName <FirstName> -LastName <LastName> -UserPrincipalName <Account> -UsageLocation <CountryCode> -LicenseAssignment <AccountSkuID> [-Password <Password>]


Eg - New-MsolUser -DisplayName “John” -FirstName “John” -LastName “Abraham” -UserPrincipalName “[email protected]” -UsageLocation “US” -LicenseAssignment “PlayGround:ENTERPRISEPACK” -Password “password-1”

Here ‘UserPrincipalName’ will be the user name of the subscription as well as the email id. ‘Usage Location’ is basically the country code that will be assigned to the account.’ LicenseAssignment’ information can be obtained by running the script,

Get-MsolAccountSku



We can perform the same operation from the UI. In order to do this, navigate to the Admin Center and from ‘Users’ section, select ‘Add User’.



This will open up the form where we can add the user information including first name, last name, user name, and password.



Click on ‘Add’. It will add the user to the Office 365 subscription. However, unless you have already purchased a license that can be assigned to the user, the Add button will not become active. Currently, my extra licenses have already been assigned to users and I will have to buy a new license before adding the new user.

Remove User

We can remove the user from Office 365 subscription, using the below PowerShell script:

Remove-MsolUser -UserPrincipalName “User Principal”



Similarly, we can remove the user by logging into the office 365 admin center .From the Users section, select ‘Active Users’. Select the More drop down and click on “Delete a user’.



Add the User Principal to the search box and click on Delete button to remove the user.



Edit User Properties

The user properties of an existing user in Office 365 can be edited using the ‘Set-MsolUser’ command,

Set-MsolUser -UserPrincipalName " [email protected]" -DisplayName "Priyan"



You can get an entire list of properties of the user, that can be changed using the ‘Set-MsolUser’ command from here.

We can also edit the properties of an existing user directly from the Office 365 Admin Center by going to the Active Users section. It will list out all the users present within the subscription. Select the check box against the user which will open up a pop up page where we can edit the user properties like setting an alternate email, change display name, change password etc.



Summary

Thus, we saw how to work with user accounts in Office 365. We primarily explored new user account creation, deletion, and editing the user account properties using PowerShell and Admin Center UI.