Manage Office 365 using PowerShell 5/5 (1) 10 min read

Office 365 includes two infrastructures that can manage by using PowerShell: Office 365 and Exchange Online.
When we use the term “Office 365” the meaning is the part that serves as an “envelope” to all other Office 365 Services/Applications.

This part includes components such as user and group object (Windows Azure Active Directory), Domain name’s management, mail migration, SSO (Single sign on), subscription and license management, etc.
In this article, we will review some popular administrative task using PowerShell.

PowerShell | Help & additional information

In case that you are a novice in the PowerShell environment, you can use the following link to get more information about the “first steps” such as: downloading the required PowerShell
software components, how to use the PowerShell console, running a PowerShell script, etc.

Read more
Link Table

PowerShell Naming Conventions & general information

If you want to get more information about the Naming Conventions that we use for this article and get some general tips about: how to work with the PowerShell, read the article: Help and additional information – o365info.com PowerShell articles

Create remote PowerShell session

Before we can use the required PowerShell commands, we need to download and install the Office 365 cmdlets + create remote PowerShell session to Office 365 or Exchange Online. If you need more information about how to create a remote PowerShell session read the following articles: Part 2: Connect to Office 365 by using Remote PowerShell and Part 3: Connect to Exchange Online by using Remote PowerShell

How to use a PowerShell script

Most of the PowerShell articles include a PowerShell script that simplifies the use of the PowerShell commands. If you want to get more information about: How to use a PowerShell script, read the article: Connect to Office 365 and Exchange Online using a script

PowerShell command and Script languish in more details

If you are new to the PowerShell world, you can read more information about PowerShell in Office 365 environment in the article: The Power of PowerShell

Section A: Office 365 users Password management


Set Password never expired for Office 365 user

PowerShell command Syntax

PowerShell command Example

Disable Password never expired option for a Office 365 user

PowerShell command Syntax

PowerShell command Example

Set Password never expired for ALL Office 365 users (BulkMode)

PowerShell command Syntax

Set a Predefined Password for Office 365 user

PowerShell command Syntax

PowerShell command Example

Set a Predefined Password for Office 365 users imported from a CSV File

Step 1: Export Office 365 users account

Predefined Password-CSV
PowerShell command Syntax

Step 2: Set a Predefined Password

Example: Step 1: Export Office 365 users account

PowerShell command Example

Create new Office 365 user and set a unique temporary password by import the information from CSV file

PowerShell command Example

Set a Temporary Password for a specific user

PowerShell command Syntax

PowerShell command Example

Set a Temporary Password for all Office 365 users (BulkMode)

PowerShell command Syntax

PowerShell command Example

Set Office 365 Password Policy

PowerShell command Syntax

PowerShell command Example

Display Password settings for all Office 365 users

PowerShell command Syntax

Display information about Office 365 Password Policy

PowerShell command Syntax

PowerShell command Example

Section B: User Principal Name (UPN) management


Change User login name “(UPN)” for a specific user

PowerShell command Syntax

PowerShell command Example

Change user login name “(UPN)” for ALL Office 365 users, exclude admin (BulkMode)

PowerShell command Syntax

Section C: License management


Display information about service that included in Specific license plan

PowerShell command Syntax

Display information about available licenses type

PowerShell command Syntax

Display information about all users and there licenses type

PowerShell command Syntax

Display information about specific license plan

PowerShell command Syntax

Display information about Subscription

PowerShell command Syntax

Display all Users with license

PowerShell command Syntax

Display all Users without a license

PowerShell command Syntax

Display information about License Options assigned to User

PowerShell command Syntax

Display information about License Options assigned to ALL Users

PowerShell command Syntax

Bulk licensing: Assign license by using CSV File

PowerShell command Syntax

PowerShell command Example

Assign license by importing from a file + Export to file and save password

PowerShell command Syntax

PowerShell command Example

Assign license for all the Office 365 that Don’t have license (BulkMode)

Step 1: The first command will display a list of available license type .

PowerShell command Syntax

Step 2: The second command will be used for assigning the license <Licenses>

PowerShell command Example

Assign specific service for Office 365 user

Sku Part Number’s reference:

ENTERPRISEPACK Sku:
OfficeSUBSCRIPTION (Office Professional Plus)
MCOSTANDARD (Lync)
SHAREPOINTWAC (Office Web Apps)
SHAREPOINTENTERPRISE (SharePoint online)
EXCHANGE_S_ENTERPRISE (Exchange online)
DESKLESSWOFFPACK Sku:
SHAREPOINTWAC
SHAREPOINTDESKLESS
EXCHANGE_S_DESKLESS
EXCHANGEARCHIVE Sku
EXCHANGE_S_ARCHIVE
1. The first command will display a Display information about service that included in Specific license plan.

PowerShell command Syntax

2. The second command will Create a variable named: $OnlyOffice that will “contain” the values of all disabled services beside Office.

3. The third command will assign a license to a user by using the variable the disable all other service beside the Office service.

Set location for unlicensed users

PowerShell command Syntax

Bulk removal of unlicensed users

PowerShell command Syntax

Export information about users without a License

PowerShell command Syntax

PowerShell command Example

Section D: Usage location management


Set Usage location for Specific user

PowerShell command Syntax

PowerShell command Example

“fix” Usage location for Office 365 users

PowerShell command Syntax

PowerShell command Example

Set Usage location for un-licensed Office 365 users

PowerShell command Syntax

PowerShell command Example

Set Usage location to users from specific department

PowerShell command Syntax

PowerShell command Example

Section E: Display and Export information about Office 365 environment


Display a list of Office 365 users

PowerShell command Syntax

Display a list of Office 365 Global Administrators

PowerShell command Syntax

PowerShell command Example

Display list of services assigned to user

PowerShell command Syntax

Display list of users and their currently License

PowerShell command Syntax

Find users UPN with a specific Domain name suffix

PowerShell command Syntax

PowerShell command Example

Display a list of user from a specific department

PowerShell command Syntax

PowerShell command Example

Export list of users and their License to: CSV file

PowerShell command Syntax

PowerShell command Example

Export information about Office 365 users mailbox to CSV file | Export list of all Office 365 users

PowerShell command Syntax

Export information about Office 365 users mailbox to CSV file | Export list of all Office 365 users with License

PowerShell command Syntax

Export information about Office 365 users mailbox to CSV file | Export list of all Office 365 users without License

PowerShell command Syntax

Export list of o365 users UPN + Email Address to: HTML file

PowerShell command Syntax

” Get-MsolUser | Select UserPrincipalName,FirstName,LastName,DisplayName,@{Name=“ProxyAddresses”;Expression={$_.ProxyAddresses | ForEach-Object {$_.tostring() + “`n”}}} | ConvertTo-Html -head $htstyle -Body “Office 365 users list” | Out-File c:\temp\o365users.htm

Section F: Office 365 Recycle bin


Delete Office 365 User Account

PowerShell command Syntax

PowerShell command Example

Delete Office 365 User Account Without a license (BulkMode)

PowerShell command Syntax

Restore Deleted User account by using the User UPN

PowerShell command Syntax

PowerShell command Example

Restore Deleted User account by using the User GUID

PowerShell command Syntax

PowerShell command Example

Delete (Remove) Specific user account from the Recycle bin

PowerShell command Syntax

PowerShell command Example

Delete (Remove) ALL user account from the Recycle bin (BulkMode)

PowerShell command Syntax

Display a list of ALL deleted User accounts

PowerShell command Syntax

Display information about Specific deleted User account

PowerShell command Syntax

PowerShell command Example

Delete Office 365 User Account

PowerShell command Syntax

PowerShell command Example

PowerShell command syntax – Office 365 | Article series index

Now it’s Your Turn!
It is important for us to know your opinion on this article


Summary
Manage Office 365 using PowerShell
Article Name
Manage Office 365 using PowerShell
Description
Office 365 includes two infrastructures that can manage by using PowerShell: Office 365 and Exchange Online. When we use the term “Office 365” the meaning is the part that serves as an “envelope” to all other Office 365 Services/Applications.
Author
Publisher Name
o365info.com
Publisher Logo

Related Post

Please rate this

Eyal Doron on EmailEyal Doron on FacebookEyal Doron on GoogleEyal Doron on LinkedinEyal Doron on PinterestEyal Doron on RssEyal Doron on TwitterEyal Doron on WordpressEyal Doron on Youtube
Eyal Doron
Share your knowledge.
It’s a way to achieve immortality.
Dalai Lama

5 Responses to “Manage Office 365 using PowerShell”

  1. Just an FYI – at present, if you set PasswordNeverExpires for an account to $true, then the user can’t change their password in OWA. They will get a message along the lines of “Sorry, you can’t change your password here. Contact your administrator.”

    The fix seems to be to set the domain’s password policy (Set-MsolPasswordPolicy) so that passwords expire far into the future (9999 days is good), then set PasswordNeverExpires to $false. This will allow users to change their password if they want, but won’t force them to any time soon.

    • Hi, I need to move all of our users from one licence type to another. Any ideas how we can do that? I think we need to remove their licences then re-add them. Unfortunately I couldn’t find exactly what I needed on here.

      • Tawsif Mulani Reply

        Set-MsolUserLicense -UserPrincipalName [email protected] -AddLicenses
        “contoso:ENTERPRISEPACK” -RemoveLicenses “contoso:Standardpack”

        I know, its a very old post, however if someone reads it today will get the ans.

  2. Hi All,

    How can I export out those user account is been disabled from office 365 into cvs files?

Leave a Reply

Your email address will not be published. Required fields are marked *