Remove the Wiki tab!

teams

As I understand, not that many use the wiki tab in Teams. Could be that I’m wrong. Anyway, her is a script that removes the Wiki tab from every channel in every team in your tenant.

#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 = "xxxx"
$tenantId = "xxxx"
$clientSecret = "xxxxx"
# 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"
}
}
}
}
}
view raw RemoveWiki.ps1 hosted with ❤ by GitHub

 

 

7 thoughts on “Remove the Wiki tab!

  1. Which API permissions do I have to set?
    I always get

    Invoke-RestMethod : {
    “error”: {
    “code”: “Authorization_RequestDenied”,
    “message”: “Insufficient privileges to complete the operation.”,

    Like

Leave a comment