Managing Microsoft Teams With Office 365 CLI Commands

 

Office 365 CLI is a handy and useful PnP open source project which allows Office 365 administrators to perform administrative tasks on our Office 365 tenant. If you want to get a basic understanding, I would suggest you to go through this link.

Installation

Office 365 CLI is available as an npm package and can be installed through node js command prompt. As for this article, we would be using the beta release to test Microsoft teams command. Run the below command on node js command prompt to install the next beta release (I choose this to check new features, you can install stable release if you are using it for production use).
npm install -g @pnp/office365-cli@next

 

To install the latest stable release, use the below command.
npm i -g @pnp/office365-cli

 

Get Office 365 CLI prompt

To get Office 365 CLI prompt on which we can run Office 365 command, run the below in node.js command. Refer to the above screenshot for output.
office365

 

Login to Office 365

login

 

It will display the below message.

Open the below URL in the browser and we should see the screen to enter code.
https://microsoft.com/devicelogin
Complete the self-explanatory login procedure. We should see the below screens one by one.

Close the browser and go back to the node.js command prompt. With this, you have successfully logged in to Office 365 and authenticated your PnP CLI to run commands on your tenant.
Let us see what team specific commands are available.
help teams

 

For the sake of this article, let us create a new Microsoft team from CLI. We would be using below sample command.
teams team add [options]         Adds a new Microsoft Teams team

 

Run below command with actual parameters.

teams team add --name 'NewMS team from Office 365 CLI' --description 'Team created from Office 365 CLI'

 

 

We should get the output as below in NodeJS command prompt. Copy this Team Id handy somewhere we will use this again in the below steps.

Now let us go to https://teams.microsoft.com to check new team is created.

Install an SPFx App to Microsoft team

Next, let us do something fancy, we will add an SPFx web part (also marked as Teams tab in webpart.manifest.json). To know details about this you can refer to this article. I already have this SPFx app installed in app catalog which contains this ‘AllPlatformWebPart’.
First, let us get the ID of this web part.
teams app list

 

Next, we will use teams team app install command to install webpart to team
teams app install --appId 4440558e-8c73-4597-abc7-3644a64c4bce --teamId 2609af39-7775-4f94-a3dc-0dd67657e900

 

Once successful, we can see below event added in Teams channel.

Please note, to add a web part to the tab – no command is yet available.  So, we have to use UI to add as a tab in Teams. To see if our web part is available, refer to the below screenshot. Click on + sign besides tabs like Conversations, Files, Wiki.

Other commands

Below is another list of commands available to manage specific Microsoft team. We can remove, archive, clone, set some settings, unarchive specific team.

Let us try some random commands and see what we can get
Get channel Id
  1. teams channel list –teamId 1912ec78-9508-4fd8-b1ff-3d82731df039

Output

displayName: General
id : 19:33fc24b9d12e4564b8ef54ca2bb42b21@thread.skype
Get Messages from specific team
teams message list --teamId 1912ec78-9508-4fd8-b1ff-3d82731df039 --channelId 19:33fc24b9d12e4564b8ef54ca2bb42b21@thread.skype

 

Output

Get teams tab list
teams tab list --teamId 11912ec78-9508-4fd8-b1ff-3d82731df039 --channelId 19:33fc24b9d12e4564b8ef54ca2bb42b21@thread.skype

 

Output

With this, I would like to conclude this article. I hope you got an idea on how we can use Office 365 CLI commands to manage Microsoft teams and what all type of commands are available and also seen some of the commands in action with output.
Hope you enjoyed reading..!!

Note – This article was originally published at this link.

(Visited 12 times, 1 visits today)