<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rajesh</title>
    <description>The latest articles on DEV Community by Rajesh (@rjesh).</description>
    <link>https://dev.to/rjesh</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F139413%2Fad09e23f-71cd-42ce-b94f-341af7b0c37d.jpg</url>
      <title>DEV Community: Rajesh</title>
      <link>https://dev.to/rjesh</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rjesh"/>
    <language>en</language>
    <item>
      <title>Delete multiple Microsoft Teams using the script </title>
      <dc:creator>Rajesh</dc:creator>
      <pubDate>Tue, 10 Mar 2020 16:04:20 +0000</pubDate>
      <link>https://dev.to/rjesh/delete-multiple-microsoft-teams-using-the-script-2f1d</link>
      <guid>https://dev.to/rjesh/delete-multiple-microsoft-teams-using-the-script-2f1d</guid>
      <description>&lt;p&gt;This is a cross-post from &lt;a href="https://rjesh.com/delete-all-teams/"&gt;rjesh.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lately, I have been working on creating a Teams template using Graph APIs and PnP Tenant template. Quickly, I accumulated a lot of Teams and decided to do a clean-up. I have achieved it by combining &lt;a href="https://aka.ms/o365cli"&gt;Office 365 CLI&lt;/a&gt; with PowerShell Core. My goal is to delete only the specific teams and not everything in my tenant, and for all my test teams I have used a naming convention which starts with 'RJ'.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell?view=powershell-7"&gt;Install PowerShell Core&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://pnp.github.io/office365-cli/#installation"&gt;Install Office 365 CLI&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;## Get teams to delete&lt;/span&gt;
&lt;span class="nv"&gt;$teams&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; o365 teams team list &lt;span class="nt"&gt;-o&lt;/span&gt; json &lt;span class="sb"&gt;`&lt;/span&gt;
&lt;span class="nt"&gt;--query&lt;/span&gt; &lt;span class="s1"&gt;'[?starts_with(displayName, `RJ`) == `true`].id'&lt;/span&gt; &lt;span class="sb"&gt;`&lt;/span&gt;
| ConvertFrom-Json

foreach &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$team&lt;/span&gt;  &lt;span class="k"&gt;in&lt;/span&gt;  &lt;span class="nv"&gt;$teams&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    Write-Host  &lt;span class="s2"&gt;"Deleting..."&lt;/span&gt;  &lt;span class="nv"&gt;$team&lt;/span&gt; &lt;span class="nt"&gt;-ForegroundColor&lt;/span&gt; Green
    o365 teams team remove &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nv"&gt;$team&lt;/span&gt; &lt;span class="nt"&gt;--confirm&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Above is a very simple script (✌🏼yay it works in Mac, PC and even in Cloud Shell ), the key thing to notice here is &lt;a href="https://twitter.com/office365cli"&gt;@office365cli&lt;/a&gt; support for --query parameter which uses &lt;a href="http://jmespath.org/"&gt;JMESPath&lt;/a&gt;. In the query parameter, I have used starts_with function to get only my test Teams which starts with the display name 'RJ' and used team remove command to get rid of them.&lt;/p&gt;

&lt;p&gt;You can change the query parameter as required to get the filtered result. For example, if you want to get all Teams except "Mark 8 Project Team"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt; o365 teams team list &lt;span class="nt"&gt;-o&lt;/span&gt; json &lt;span class="nt"&gt;--query&lt;/span&gt; &lt;span class="s1"&gt;'[?displayName != `Mark8 Project Team`]'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt; Just like me If you are wondering, even after deleting the Teams it still shows up in the Teams App then you should read this - &lt;a href="https://techcommunity.microsoft.com/t5/microsoft-teams/deleted-team-still-appearing-in-apps/m-p/1054677"&gt;techcommunity post&lt;/a&gt; which details about the latency of few hours required.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you want to delete the Office 365 groups then use the below script&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;## Get groups to delete&lt;/span&gt;
&lt;span class="nv"&gt;$groups&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; o365 aad o365group list &lt;span class="nt"&gt;-o&lt;/span&gt; json &lt;span class="sb"&gt;`&lt;/span&gt;
&lt;span class="nt"&gt;--query&lt;/span&gt; &lt;span class="s1"&gt;'[?starts_with(displayName, `SET`) == `true`].id'&lt;/span&gt; &lt;span class="sb"&gt;`&lt;/span&gt;
| ConvertFrom-Json

foreach &lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$group&lt;/span&gt;  &lt;span class="k"&gt;in&lt;/span&gt;  &lt;span class="nv"&gt;$groups&lt;/span&gt;&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
    Write-Host  &lt;span class="s2"&gt;"Deleting..."&lt;/span&gt;  &lt;span class="nv"&gt;$group&lt;/span&gt; &lt;span class="nt"&gt;-ForegroundColor&lt;/span&gt; Green
    o365 aad o365group remove &lt;span class="nt"&gt;-i&lt;/span&gt; &lt;span class="nv"&gt;$group&lt;/span&gt; &lt;span class="nt"&gt;--confirm&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Photo by &lt;a href="https://unsplash.com/@fantasyflip?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Philipp Katzenberger&lt;/a&gt; on &lt;a href="https://unsplash.com"&gt;Unsplash&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>microsoftteams</category>
      <category>script</category>
      <category>powershellcore</category>
      <category>office365cli</category>
    </item>
  </channel>
</rss>
