Last active
July 23, 2020 15:53
-
-
Save garrytrinder/4df2aeaf9dd66c4375308874eb7def63 to your computer and use it in GitHub Desktop.
Removes Wiki Tab from Microsoft Teams Channel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory = $true)] | |
[string] | |
$groupMailNickname, | |
[Parameter(Mandatory = $true)] | |
[string] | |
$channelName | |
) | |
$ErrorActionPreference = 'Stop' | |
$groups = o365 aad o365group list --query "[?mailNickname=='$groupMailNickname'].{id:id}" -o json | ConvertFrom-Json | |
if ($null -eq $groups) { Write-Error "A team with the mailNickname $groupMailNickname was not found" } | |
$channels = o365 teams channel list --teamId $groups[0].id --query "[?displayName=='$channelName']" -o json | ConvertFrom-Json | |
if ($null -eq $channels) { Write-Error "A channel with the name $channelName was not found in the team" } | |
$tabs = o365 teams tab list --teamId $groups[0].id --channelId $channels[0].id --query "[?teamsApp.id=='com.microsoft.teamspace.tab.wiki']" -o json --pretty | ConvertFrom-Json | |
if ($null -eq $tabs) { Write-Error "A Wiki tab was not found on the channel" } | |
$token = o365 util accesstoken get -r "https://graph.microsoft.com" --new | |
$tabs | ForEach-Object { | |
$options = @{ | |
Method = "Delete" | |
Uri = "https://graph.microsoft.com/v1.0/teams/$($groups[0].id)/channels/$($channels[0].id)/tabs/$($_.id)" | |
Headers = @{ | |
"Authorization" = "Bearer $token" | |
} | |
} | |
try { | |
Invoke-RestMethod @options | |
Write-Host "Wiki Tab was succesfully removed from channel" -ForegroundColor Green | |
} | |
catch { | |
Write-Host "There was an issue removing Wiki Tab from the channel" | |
Write-Host $_.Exception.Message | |
} | |
} |
@stjeloma you may want to check out this sample in the Office 365 CLI docs which improves on this gist as the remove tab command was not in the CLI at the time this was written but has since been added.
https://pnp.github.io/office365-cli/sample-scripts/teams/remove-wikitab-teams/
Excellent Garry, thanks!!
My pleasure, happy to help 😊 #SharingIsCaring
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Done. Thanks for pointing those out @stjeloma 👍