Home

How to find Teams group with microsoft graph API

%3CLINGO-SUB%20id%3D%22lingo-sub-69120%22%20slang%3D%22en-US%22%3EHow%20to%20find%20Teams%20group%20with%20microsoft%20graph%20API%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-69120%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20would%20like%20to%20only%20listed%20Teams%20group%20.%20How%20it%20is%20possible%20to%20filter%20it%20%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20for%20your%20help.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-69120%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EMicrosoft%20Teams%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-200813%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20find%20Teams%20group%20with%20microsoft%20graph%20API%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-200813%22%20slang%3D%22en-US%22%3E%3CP%3EUsing%20the%20Graph%20API%20from%20C%23%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Eprivate%3C%2FFONT%3E%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Ebool%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20IsTeam(UnifiedGroupEntity%20group)%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%7B%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3E%26nbsp%3B%20try%20%7B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Evar%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20task%20%3D%20GetChannelsAsync(group)%3B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Eif%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20(!task.Wait(5000))%26nbsp%3B%7B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Ethrow%3C%2FFONT%3E%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Enew%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20Exception(%3C%2FFONT%3E%3CFONT%20color%3D%22%23a31515%22%20face%3D%22Consolas%22%20size%3D%222%22%3E%22GetChannelsAsync%20attempt%20timed%20out%22%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E)%3B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Ereturn%3C%2FFONT%3E%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Etrue%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%3B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%20%7D%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Ecatch%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20(Exception%20exc)%20%7B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3EConsole.WriteLine(%3C%2FFONT%3E%3CFONT%20color%3D%22%23a31515%22%20face%3D%22Consolas%22%20size%3D%222%22%3E%22Team%20call%20failed%3A%20%22%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20%2B%20exc.Message)%3B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Ereturn%3C%2FFONT%3E%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Efalse%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%3B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%20%7D%3C%2FP%3E%3CP%3E%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Eprivate%3C%2FFONT%3E%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Easync%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20Task%20GetChannelsAsync(UnifiedGroupEntity%20group)%20%7B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%26nbsp%3B%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Eusing%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20(HttpClient%20httpClient%20%3D%20%3C%2FFONT%3E%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Enew%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20HttpClient())%20%7B%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3EhttpClient.DefaultRequestHeaders.Add(%3C%2FFONT%3E%3CFONT%20color%3D%22%23a31515%22%20face%3D%22Consolas%22%20size%3D%222%22%3E%22Authorization%22%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%2C%20%3C%2FFONT%3E%3CFONT%20color%3D%22%23a31515%22%20face%3D%22Consolas%22%20size%3D%222%22%3E%22Bearer%20%22%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%2B%20AccessToken)%3B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Evar%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20url%20%3D%20%3C%2FFONT%3E%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Estring%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E.Format(%3C%2FFONT%3E%3CFONT%20color%3D%22%23a31515%22%20face%3D%22Consolas%22%20size%3D%222%22%3E%22%3CA%20href%3D%22https%3A%2F%2Fgraph.microsoft.com%2Fbeta%2FGroups%2F%7B0%7D%2Fchannels%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgraph.microsoft.com%2Fbeta%2FGroups%2F%7B0%7D%2Fchannels%3C%2FA%3E%22%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%2C%20group.GroupId)%3B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3EHttpResponseMessage%20hrm%20%3D%20httpClient.GetAsync(url).Result%3B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Eif%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20(hrm.IsSuccessStatusCode)%20%7B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3EStream%20data%20%3D%20%3C%2FFONT%3E%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Eawait%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20hrm.Content.ReadAsStreamAsync()%3B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3EStreamReader%20reader%20%3D%20%3C%2FFONT%3E%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Enew%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20StreamReader(data)%3B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Estring%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20text%20%3D%20reader.ReadToEnd()%3B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%2F%2FThere%20are%20better%20ways%20to%20read%20the%20json%20result%2C%20hackish%20code%20below%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Evar%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20vstart%20%3D%20text.IndexOf(%3C%2FFONT%3E%3CFONT%20color%3D%22%23a31515%22%20face%3D%22Consolas%22%20size%3D%222%22%3E%22%5C%22value%5C%22%3A%5B%22%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E)%2B1%3B%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Evar%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20vend%20%3D%20text.IndexOf(%3C%2FFONT%3E%3CFONT%20color%3D%22%23a31515%22%20face%3D%22Consolas%22%20size%3D%222%22%3E%22%5D%22%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%2C%20vstart)%3B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Evar%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20split%20%3D%20SplitJsonArray(text.Substring(vstart%2C%20vend%20-%20vstart))%3B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3EDataContractJsonSerializer%20serializer%20%3D%20%3C%2FFONT%3E%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Enew%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20DataContractJsonSerializer(%3C%2FFONT%3E%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Etypeof%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E(ChannelResponse))%3B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Eforeach%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20(%3C%2FFONT%3E%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Estring%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20cjson%20%3C%2FFONT%3E%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Ein%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20split)%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%7B%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Evar%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20channel%20%3D%20(ChannelResponse)serializer.ReadObject(%3C%2FFONT%3E%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Enew%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20MemoryStream(Encoding.Unicode.GetBytes(cjson)))%3B%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%26nbsp%3B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%26nbsp%3B%26nbsp%3B%26nbsp%3B%20%7D%3C%2FP%3E%3CP%3E%26nbsp%3B%20%7D%3C%2FP%3E%3CP%3E%7D%3C%2FP%3E%3CP%3E%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Epublic%3C%2FFONT%3E%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Eclass%3C%2FFONT%3E%20%3CFONT%20color%3D%22%232b91af%22%20face%3D%22Consolas%22%20size%3D%222%22%3EChannelResponse%20%7B%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Epublic%3C%2FFONT%3E%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Estring%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20id%20%7B%20%3C%2FFONT%3E%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Eget%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%3B%20%3C%2FFONT%3E%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Eset%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%3B%20%7D%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Epublic%3C%2FFONT%3E%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Estring%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20displayname%20%7B%20%3C%2FFONT%3E%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Eget%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%3B%20%3C%2FFONT%3E%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Eset%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%3B%20%7D%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Epublic%3C%2FFONT%3E%20%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Estring%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%20description%20%7B%20%3C%2FFONT%3E%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Eget%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%3B%20%3C%2FFONT%3E%3CFONT%20color%3D%22%230000ff%22%20face%3D%22Consolas%22%20size%3D%222%22%3Eset%3C%2FFONT%3E%3CFONT%20face%3D%22Consolas%22%20size%3D%222%22%3E%3B%20%7D%3C%2FFONT%3E%3C%2FP%3E%3CP%3E%7D%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-71755%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20find%20Teams%20group%20with%20microsoft%20graph%20API%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-71755%22%20slang%3D%22en-US%22%3E%3CP%3EPlease%20use%20the%20below%20script.%20To%20run%20this%20script%20you%20need%20to%20install%20SPO%20PnP%20Powershell%20module%20from%20%3CA%20href%3D%22https%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-PowerShell%2Freleases%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%20noopener%20noreferrer%22%3Ehttps%3A%2F%2Fgithub.com%2FSharePoint%2FPnP-PowerShell%2Freleases%3C%2FA%3E.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%3EConnect-PnPMicrosoftGraph%20-Scopes%20%E2%80%9CGroup.ReadWrite.All%E2%80%9D%2C%22Group.Read.All%22%2C%22Directory.Read.All%22%2C%22Directory.AccessAsUser.All%22%2C%22User.ReadBasic.All%22%0A%24accesstoken%20%3DGet-PnPAccessToken%0A%24group%20%3D%20Invoke-RestMethod%20-Headers%20%40%7BAuthorization%20%3D%20%22Bearer%20%24accesstoken%22%7D%20-Uri%20%20https%3A%2F%2Fgraph.microsoft.com%2Fbeta%2FGroups%20-Method%20Get%0A%24Values%3D%24group.value%0A%24TeamsList%20%3D%20%40()%0A%0Aforeach(%24value%20in%20%24values)%0A%7B%0A%20%20%20%20if(%24value.groupTypes%20-eq%20%22Unified%22)%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%24id%3D%20%24value.id%0A%0A%20%20%20%20%20%20%20%20%20%24team%20%3D%20Invoke-RestMethod%20-Headers%20%40%7BAuthorization%20%3D%20%22Bearer%20%24accesstoken%22%7D%20-Uri%20%20https%3A%2F%2Fgraph.microsoft.com%2Fbeta%2FGroups%2F%24id%2Fchannels%20-Method%20Get%0A%0A%20%20%20%20%20%20%20%20%20If(%24team.value.id.count%20-ge%201)%0A%20%20%20%20%20%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%24Owner%20%3D%20Invoke-RestMethod%20-Headers%20%40%7BAuthorization%20%3D%20%22Bearer%20%24accesstoken%22%7D%20-Uri%20%20https%3A%2F%2Fgraph.microsoft.com%2Fbeta%2FGroups%2F%24id%2Fowners%20-Method%20Get%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%24Teams%20%3D%20%22%22%20%7C%20Select%20%22TeamsName%22%2C%22TeamType%22%2C%22Channelcount%22%2C%22ChannelName%22%2C%22Owners%22%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%24Teams.TeamsName%20%3D%20%24value.displayname%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%24Teams.TeamType%20%3D%20%24value.visibility%20%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%24Teams.Channelcount%20%3D%20%24team.value.id.count%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%24Teams.ChannelName%20%3D%20%24team.value.displayName%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%24Teams.Owners%20%3D%20%24Owner.value.userPrincipalName%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%24TeamsList%2B%3D%20%24Teams%0A%20%20%20%20%20%20%20%20%20%20%20%20%20%24Teams%3D%24null%0A%0A%20%20%20%20%20%20%20%20%20%7D%0A%20%20%20%20%20%7D%0A%7D%0A%24TeamsList%20%20%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-69321%22%20slang%3D%22en-US%22%3ERE%3A%20How%20to%20find%20Teams%20group%20with%20microsoft%20graph%20API%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-69321%22%20slang%3D%22en-US%22%3ENot%20yet%2C%20afaik.%3C%2FLINGO-BODY%3E
Deleted
Not applicable

Hello,

 

I would like to only listed Teams group . How it is possible to filter it ?

 

Thanks for your help.

3 Replies
Highlighted
Not yet, afaik.

Please use the below script. To run this script you need to install SPO PnP Powershell module from https://github.com/SharePoint/PnP-PowerShell/releases.

 

Connect-PnPMicrosoftGraph -Scopes “Group.ReadWrite.All”,"Group.Read.All","Directory.Read.All","Directory.AccessAsUser.All","User.ReadBasic.All"
$accesstoken =Get-PnPAccessToken
$group = Invoke-RestMethod -Headers @{Authorization = "Bearer $accesstoken"} -Uri  https://graph.microsoft.com/beta/Groups -Method Get
$Values=$group.value
$TeamsList = @()

foreach($value in $values)
{
    if($value.groupTypes -eq "Unified")
    {
         $id= $value.id

         $team = Invoke-RestMethod -Headers @{Authorization = "Bearer $accesstoken"} -Uri  https://graph.microsoft.com/beta/Groups/$id/channels -Method Get

         If($team.value.id.count -ge 1)
         {
             $Owner = Invoke-RestMethod -Headers @{Authorization = "Bearer $accesstoken"} -Uri  https://graph.microsoft.com/beta/Groups/$id/owners -Method Get
             $Teams = "" | Select "TeamsName","TeamType","Channelcount","ChannelName","Owners"
             $Teams.TeamsName = $value.displayname
             $Teams.TeamType = $value.visibility 
             $Teams.Channelcount = $team.value.id.count
             $Teams.ChannelName = $team.value.displayName
             $Teams.Owners = $Owner.value.userPrincipalName
             $TeamsList+= $Teams
             $Teams=$null

         }
     }
}
$TeamsList  

Using the Graph API from C#

 

private bool IsTeam(UnifiedGroupEntity group)

{

  try {

    var task = GetChannelsAsync(group);

    if (!task.Wait(5000)) {

      throw new Exception("GetChannelsAsync attempt timed out");

      }

    return true;

   } catch (Exception exc) {

    Console.WriteLine("Team call failed: " + exc.Message);

    return false;

   }

}

 

private async Task GetChannelsAsync(UnifiedGroupEntity group) {

  using (HttpClient httpClient = new HttpClient()) {

   httpClient.DefaultRequestHeaders.Add("Authorization", "Bearer "+ AccessToken);

   var url = string.Format("https://graph.microsoft.com/beta/Groups/{0}/channels", group.GroupId);

     HttpResponseMessage hrm = httpClient.GetAsync(url).Result;

   if (hrm.IsSuccessStatusCode) {

     Stream data = await hrm.Content.ReadAsStreamAsync();

     StreamReader reader = new StreamReader(data);

     string text = reader.ReadToEnd();

     //There are better ways to read the json result, hackish code below

     var vstart = text.IndexOf("\"value\":[")+1;

     var vend = text.IndexOf("]", vstart);

     var split = SplitJsonArray(text.Substring(vstart, vend - vstart));

     DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(ChannelResponse));

     foreach (string cjson in split)

        {

      var channel = (ChannelResponse)serializer.ReadObject(new MemoryStream(Encoding.Unicode.GetBytes(cjson))); 

        }

     }

  }

}

public class ChannelResponse {

  public string id { get; set; }

  public string displayname { get; set; }

  public string description { get; set; }

}

Related Conversations
flashing a white screen while open new tab
cntvertex in Discussions on
13 Replies
Tabs and Dark Mode
cjc2112 in Discussions on
22 Replies
Stable version of Edge insider browser
HotCakeX in Discussions on
35 Replies
How to Prevent Teams from Auto-Launch
chenrylee in Microsoft Teams on
28 Replies
PacketMon Components are not loading in WAC 1909
HotCakeX in Windows Admin Center on
2 Replies