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). 
  1. npm install -g @pnp/office365-cli@next  
To install the latest stable release, use the below command.
  1. npm i -g @pnp/office365-cli  
Managing Microsoft Teams With Office 365 CLI Commands
 

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.
  1. office365  

Login to Office 365

  1. login  
It will display the below message.
 
Managing Microsoft Teams With Office 365 CLI Commands
 
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.
 
Managing Microsoft Teams With Office 365 CLI Commands
 
Managing Microsoft Teams With Office 365 CLI Commands 
 
Managing Microsoft Teams With Office 365 CLI Commands 
 
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. 
  1. help teams  
Managing Microsoft Teams With Office 365 CLI Commands
 
For the sake of this article, let us create a new Microsoft team from CLI. We would be using below sample command.
  1. teams team add [options]         Adds a new Microsoft Teams team  
Run below command with actual parameters.
  1. 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.
 
Managing Microsoft Teams With Office 365 CLI Commands
 
Now let us go to https://teams.microsoft.com to check new team is created.
 
Managing Microsoft Teams With Office 365 CLI Commands

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.
  1. teams app list  
Managing Microsoft Teams With Office 365 CLI Commands
 
Next, we will use teams team app install command to install webpart to team
  1. 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.
 
Managing Microsoft Teams With Office 365 CLI Commands
 
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.
 
Managing Microsoft Teams With Office 365 CLI Commands
 

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.
 
Managing Microsoft Teams With Office 365 CLI Commands
 
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
 
Get Messages from specific team  
  1. teams message list --teamId 1912ec78-9508-4fd8-b1ff-3d82731df039 --channelId 19:[email protected]  
Output
 
Managing Microsoft Teams With Office 365 CLI Commands
 
Get teams tab list
  1. teams tab list --teamId 11912ec78-9508-4fd8-b1ff-3d82731df039 --channelId 19:33fc[email protected]  
Output
 
Managing Microsoft Teams With Office 365 CLI Commands
 
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..!! 


Similar Articles