Create_Teams.csv

TeamsName,MailNickname,TeamType,ChannelName,Owners,Members
NL 03 PROJECTS Private,NL03PROJECTSPrivate,Private,E 664 Wageningen Plus Ultra II;E 691 Plus Ultra Groningen,admin@werkindecloud.onmicrosoft.com,iris@werkinde.cloud;Switch@werkinde.cloud;demo@werkinde.cloud;test@werkinde.cloud
function Create-Channel
{   
   param (   
             $ChannelName,$GroupId,$MembershipType
         )   
    Process
    {
        try
            {
                $teamchannels = $ChannelName -split ";" 
                if($teamchannels)
                {
                    for($i =0; $i -le ($teamchannels.count - 1) ; $i++)
                    {
                        New-TeamChannel -GroupId $GroupId -DisplayName $teamchannels[$i] -MembershipType $MembershipType
                    }
                }
            }
        Catch
            {
            }
    }
}

function Add-Users
{   
    param(   
             $Users,$GroupId,$CurrentUsername,$Role
          )   
    Process
    {
        
        try{
                $teamusers = $Users -split ";" 
                if($teamusers)
                {
                    for($j =0; $j -le ($teamusers.count - 1) ; $j++)
                    {
                        if($teamusers[$j] -ne $CurrentUsername)
                        {
                            Add-TeamUser -GroupId $GroupId -User $teamusers[$j] -Role $Role
                        }
                    }
                }
            }
        Catch
            {
            }
        }
}

function Create-NewTeam
{   
   param (   
             $ImportPath
         )   
  Process
    {
        #Import-Module MicrosoftTeams
        #$cred = Get-Credential
        #$username = $cred.UserName
        #Connect-MicrosoftTeams
        $teams = Import-Csv -Path $ImportPath
        foreach($team in $teams)
        {
            $getteam= get-team |where-object { $_.displayname -eq $team.TeamsName}
            If($getteam -eq $null)
            {
                Write-Host "Start creating the team: " $team.TeamsName
                $group = New-Team -MailNickname $team.MailNickname -displayname $team.TeamsName  -Visibility $team.TeamType -AllowCreateUpdateChannels $False -AllowDeleteChannels $False -AllowAddRemoveApps $False -AllowCreateUpdateRemoveTabs $False -AllowCreateUpdateRemoveConnectors $False
                Write-Host "Creating channels..."
                Create-Channel -ChannelName $team.ChannelName -GroupId $group.GroupId -MembershipType Private
                Write-Host "Adding team members..."
                Add-Users -Users $team.Members -GroupId $group.GroupId -CurrentUsername $username -Role Member 
                Write-Host "Adding team owners..."
                Add-Users -Users $team.Owners -GroupId $group.GroupId -CurrentUsername $username -Role Owner
                Write-Host "Completed creating the team: " $team.TeamsName
                $team=$null
            }
         }
    }
}

Create-NewTeam -ImportPath "C:\365\Team01.csv"

Export Group ID. Let op opnieuw verbinding maken.

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

Foreach ($Team in $AllTeams)
{       
        $TeamGUID = $Team.ToString()
        $TeamName = (Get-Team | ?{$_.GroupID -eq $Team}).DisplayName
        $TeamOwner = (Get-TeamUser -GroupId $Team | ?{$_.Role -eq 'Owner'}).Name
        $TeamMember = (Get-TeamUser -GroupId $Team | ?{$_.Role -eq 'Member'}).Name

        $TeamList = $TeamList + [PSCustomObject]@{TeamName = $TeamName; TeamObjectID = $TeamGUID; TeamOwners = $TeamOwner -join ', '; TeamMembers = $TeamMember -join ', '}
}

$TeamList | export-csv c:\temp\TeamsData.csv -NoTypeInformation
Import-Csv C:\Temp\TeamsData.csv | ForEach-Object { Set-Team -GroupId $_.TeamObjectID -AllowCreateUpdateChannels $False -AllowDeleteChannels $False -AllowAddRemoveApps $False -AllowCreateUpdateRemoveTabs $False -AllowCreateUpdateRemoveConnectors $False}

RemoveWiki.ps1

#Application logon
# Azure AD OAuth Application Token for Graph API

# Get OAuth token for a AAD Application (returned as $token)


 #Application (client) ID, tenant ID and secret

 $clientId = "XXX"

 $tenantId = "XXX"
 
 $clientSecret = "XXX"
 
 
 
 # Contruct URI
 
 $uri = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/token"
 
 
 
 # Construct Body
 
 $body1 = @{
 
     client_id     = $clientId
 
     scope         = "https://graph.microsoft.com/.default"
 
     client_secret = $clientSecret
 
     grant_type    = "client_credentials"
 
 }
 
 
 
 # Get OAuth 2.0 Token
 
 $tokenRequest = Invoke-WebRequest -Method Post -Uri $uri -ContentType "application/x-www-form-urlencoded" -Body $body1 -UseBasicParsing
  
 
 
 $token = ($tokenRequest.Content | ConvertFrom-Json).access_token
 
$token


$uri = 'https://graph.microsoft.com/v1.0/groups'

$query = Invoke-RestMethod -Method GET -Uri $uri -ContentType "application/json" -Headers @{Authorization = "Bearer $token"}
$groups = $query.value

foreach($group in $groups){
if($group.resourceProvisioningOptions -contains 'Team'){
    $id = $group.id
    $uri2 = 'https://graph.microsoft.com/v1.0/teams/'+$id+'/channels'
    $query2 = Invoke-RestMethod -Method GET -Uri $uri2 -ContentType "application/json" -Headers @{Authorization = "Bearer $token"}
    $Channels = $query2.value
    Foreach($Channel in $Channels){

        $id2 = $Channel.id
        $uri3 = 'https://graph.microsoft.com/v1.0/teams/'+$id+'/channels/'+$id2+'/tabs'

        $query3 = Invoke-RestMethod -Method GET -Uri $uri3 -ContentType "application/json" -Headers @{Authorization = "Bearer $token"}

        $tabs = $query3.value
        $WikiTabs = $tabs | Where-Object{$_.displayname -eq 'Wiki'}
        If($WikiTabs){
        Foreach($wikitab in $WikiTabs){    
        $wikitabID = $WikiTabs.id
        $uri4 = 'https://graph.microsoft.com/v1.0/teams/'+$id+'/channels/'+$id2+'/tabs/'+$wikitabID

        $query4 = Invoke-RestMethod -Method DELETE -Uri $uri4 -ContentType "application/json" -Headers @{Authorization = "Bearer $token"}
        "wikitab removed"
        }
        }





    
    }


    


}
}

API permissions

Group.ReadWrite.AllDelegated
Group.ReadWrite.AllApplication