Get Team Owner Names - Custom Action

Modified on Wed, 24 Aug 2022 at 05:01 AM

If you want to retrieve Teams Owner names in a json string without the "" characters around the names or [] around the object. This is useful for including in emails to team owners.


In PowerShell:


$AllTeams = Get-Team
$TeamList = @()

foreach ($Team in $AllTeams)
{
$TeamGUID = $Team.GroupId.ToString()
$TeamName = $Team.DisplayName
write-host $TeamName
$TeamUsers = Get-TeamUser -GroupId $TeamGUID
$TeamOwner = ($TeamUsers | Where-Object {$_.Role -eq ‘Owner’}).User
$TeamList = $TeamList + [PSCustomObject]@{
TeamName = $TeamName;
TeamObjectID = $TeamGUID;
TeamOwners = $TeamOwner -join ‘; ‘;
}
}
$TeamList | export-csv c:\temp\TeamsData.csv -NoTypeInformation


In Coreview:

{

   "id": "f2fc9d6f-50b8-49da-ad5a-4976cbc8109a",

   "title": "Get Teams Owner Names",

   "lastModified": "2022-02-09T11:56:13.3080000Z",

   "target": "Teams",

   "tags": [],

   "vars": [],

   "params": [

      {

         "name": "DisplayName",

         "type": "string",

         "isDefault": true

      },

      {

         "name": "Id",

         "type": "string",

         "isDefault": false

      }

   ],

   "columns": {

      "Id": "",

      "DisplayName": ""

   },

   "version": 4,

   "statement": "param ([string]$DisplayName, [string]$Id)\r\n\r\n$Id = \"bb4cdde2-eb41-40da-8531-7f4fd7556682\"\n$json = (Get-TeamUser -GroupId $Id -Role Owner | Select -ExpandProperty Name | ConvertTo-Json) -replace '\"', '' #-replace \",\",\"<br>\"\n\n$cleanjson = $json.Trim([char]0x005B, [char]0x005D)\n\nreturn $cleanjson"

}

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons

Feedback sent

We appreciate your effort and will try to fix the article