Cheking if a MS Team exists in tenant

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:

$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:

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.