Forum Discussion
Need details of MS teams created in last 10 mins
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 Appreciate your Kudos! Proud to contribute! 🙂 |