Governance - Scan Office 365 Groups Created with User First or Last Name using Office 365 CLI Commands


You can manage your Microsoft Office 365 tenant and SharePoint Framework projects on any platform using Office 365 CLI. No matter if you are on Windows, macOS or Linux, using Bash, Cmder or PowerShell, or using the Office 365 CLI, you can configure Office 365, manage SharePoint Framework projects and build automation scripts.
To use Office 365 CLI, you need Node.js. The CLI has been tested with Node.js versions 6 and higher, but we recommend you to use the Node.js LTS version available at the moment. For more information on installing Node.js for your platform visit
Office 365 CLI works on Windows, macOS, and Linux and you can use it with any shell on these platforms.
The Office 365 CLI is distributed as an NPM package. To use it, install it globally using:
npm i -g @pnp/office365-cli or using yarn:
yarn global add @pnp/office365-cli
Getting started
Start the Office 365 CLI by typing the following in the command line:
$ office365
o365$ _
Running the Office 365 command will start the immersive CLI with its own command prompt.
Start managing the settings of your Office 365 tenant by logging in to it, using the login command, for example,
o365$ login
To list all available commands, type in the Office 365 CLI prompt help:
o365$ help
To exit the CLI, type exit:
o365$ exit
See the User Guide to learn more about the Office 365 CLI and its capabilities.
Simple use case:
We can use the group naming policy to enforce a consistent naming strategy for groups created by users in our organization. A naming policy can help us and our users identify the function of the group. We can use the policy to block specific words from being used in group names and aliases. But what if we need to find out the list of Office 365 groups created with the user’s given name or surname as their mail? This Office 365 CLI sample script scans the Office 365 groups that may contain the user’s given name or surname as the group mail.
The filter condition can be changed as per your requirement.
The following articles describe how to add a new command to the Office 365 CLI.