# Cheking if a MS Team exists in tenant

**URL:** <https://forums.powershell.org/t/cheking-if-a-ms-team-exists-in-tenant/18011>\
**Category:** PowerShell Help\
**Created:** [November 22, 2021, 10:19am UTC](https://forums.powershell.org/t/cheking-if-a-ms-team-exists-in-tenant/18011 "2021-11-22T10:19:44Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![laage](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/laage/32/43_2.png) [@laage](https://forums.powershell.org/u/laage)\
**Post date:** [November 22, 2021, 10:19am UTC](https://forums.powershell.org/t/cheking-if-a-ms-team-exists-in-tenant/18011/1 "2021-11-22T10:19:44Z")

</div>

I’m cleaning up Teams without owners and members in our Tenant and I have very basic script which takes a list of GroupIDs from a text-file and runs them through a foreach with Remove-Team.

I wanted to implement a simple check to see if the team existed before running the Remove-Team cmdlet but it seems that the MicrosoftTeams module does things somewhat differently than what I expected.

My code looks like this right now:

```auto
$Teams = Get-Content -Path $File -Encoding UTF8

foreach ($T in $Teams) {
  $Team = $null
  $Team = Get-Team -GroupId $T -ErrorAction SilentlyContinue

  if ($null -eq $Team) {
    Write-Warning -Message "Team with GroupID: $T does not exist."
  }
  else {
    Write-Output "Deleting $($Team.DisplayName)"
    Remove-Team -GroupId $T
  }

```

I started without the `-ErrorAction SilentlyContinue` on the `Get-Team` and got the following error message and the script ended when I tested with a Team I knew had been deleted previously:

```auto
Get-Team: NotFound in /v1.0/groups/ endpoint

```

I thought that adding the `SilentlyContinue` would allow me to keep the script running, but it seems that the MicrosoftTeams module ignores the `-ErrorAction` parameter, because it still exits the script with the samme error message when it hits a previously deleted Team-GroupID.

I know Teams are based on O365 Unified groups and I can go via another module to check for the existence of the group in stead, but if possible I would like to keep the script as simple and with as few dependencies as possible.

---

<div class="post-metadata">

**Author:** ![dotnVo](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dotnVo](https://forums.powershell.org/u/dotnVo)\
**Post date:** [May 16, 2024, 8:20pm UTC](https://forums.powershell.org/t/cheking-if-a-ms-team-exists-in-tenant/18011/2 "2024-05-16T20:20:12Z")

</div>


