Need details of MS teams created in last 10 mins

Copper Contributor

I am trying to find a script which can fetch details of MS teams created in last 10 mins. I need the output to be created in 10 mins or less than 10 mins. Please advise if this is possible to achieve.

3 Replies

@Anju_Singh 

Yes, it is possible to achieve this using the Microsoft Graph API and a scripting language like Python. The Microsoft Graph API allows you to interact with Microsoft Teams and retrieve various details, including information about recently created teams.

Here's an example script using the Python programming language and the Microsoft Graph API to fetch details of MS Teams created in the last 10 minutes:

 

```python

import requests

import datetime

import time

 

# Microsoft Graph API endpoint for teams

teams_endpoint = "https://graph.microsoft.com/v1.0/groups?$filter=resourceProvisioningOptions/Any(x:x eq 'Team')&$select=id,displayName,createdDateTime"

 

# Calculate the start time 10 minutes ago

start_time = datetime.datetime.now() - datetime.timedelta(minutes=10)

 

# Convert start time to ISO 8601 format

start_time_iso = start_time.strftime("%Y-%m-%dT%H:%M:%S")

 

# Request headers

headers = {

    "Authorization": "Bearer YOUR_ACCESS_TOKEN"

}

 

# Send the request to the Microsoft Graph API

response = requests.get(teams_endpoint, headers=headers)

 

# Check the response status code

if response.status_code == 200:

    # Parse the response JSON

    data = response.json()

 

    # Filter teams created within the last 10 minutes

    recent_teams = [team for team in data["value"] if team["createdDateTime"] >= start_time_iso]

 

    # Print the details of the recent teams

    for team in recent_teams:

        team_name = team["displayName"]

        team_id = team["id"]

        created_time = team["createdDateTime"]

        print(f"Team Name: {team_name}")

        print(f"Team ID: {team_id}")

        print(f"Created Time: {created_time}")

        print("--------")

 

else:

    print(f"Error: {response.status_code} - {response.text}")

```

 

In the script above, you need to replace `"YOUR_ACCESS_TOKEN"` with an actual access token that is authorized to access the Microsoft Graph API. You can refer to the Microsoft Graph API documentation to learn more about authentication and obtaining an access token.

 

Please note that this script assumes you have the necessary permissions to access Microsoft Teams data via the Microsoft Graph API and that you have registered your application with the required permissions. Additionally, you may need to install the `requests` library using `pip install requests` if you don't have it already.

 

Keep in mind that the script's execution time may vary depending on the network latency and the number of teams created within the specified timeframe.

 

 

If I have answered your question, please mark your post as Solved

If you like my response, please give it a Like :smile:

Appreciate your Kudos! Proud to contribute! 🙂

 

I appreciate your response. Is there any way to achieve this from the PowerShell script?

Hi @Anju_Singh , 

Here's an example script that demonstrates how you can achieve this:

 

# Install and import the Microsoft Teams PowerShell module

Install-Module -Name PowerShellGet -Force -AllowClobber -SkipPublisherCheck

Install-Module -Name MicrosoftTeams -Force -AllowClobber -SkipPublisherCheck

 

# Import the module

Import-Module MicrosoftTeams

 

# Connect to Microsoft Teams using your credentials

Connect-MicrosoftTeams

 

# Retrieve all Teams

$allTeams = Get-Team

 

# Get the current time

$currentTime = Get-Date

 

# Define the time range (e.g., 10 minutes)

$timeRange = New-TimeSpan -Minutes 10

 

# Filter Teams created within the last 10 minutes

$newTeams = $allTeams | Where-Object { ($currentTime - $_.WhenCreated) -lt $timeRange }

 

# Display details of the new Teams

$newTeams | Format-Table DisplayName, WhenCreated, GroupId

 

In this script, we first install the required PowerShell module (MicrosoftTeams) if it's not already installed. Then we import the module and connect to Microsoft Teams using your credentials. After that, we retrieve all the Teams in your environment.

We then get the current time using Get-Date and define the desired time range using New-TimeSpan. In this example, we set the time range to 10 minutes.

Next, we filter the Teams based on their creation time using the Where-Object cmdlet. The Teams whose creation time falls within the defined time range are stored in the $newTeams variable.

Finally, we display the details of the newly created Teams by formatting and outputting the DisplayName, WhenCreated, and GroupId properties.

Please note that the script assumes you have the necessary permissions to access the Teams information in your environment. Additionally, make sure you have the required PowerShell module (MicrosoftTeams) installed before running the script.

 

 

 

If I have answered your question, please mark your post as Solved

If you like my response, please give it a Like :smile:

Appreciate your Kudos! Proud to contribute! 🙂