Skip to content

Instantly share code, notes, and snippets.

@garrytrinder
Last active July 23, 2020 15:53
Show Gist options
  • Save garrytrinder/4df2aeaf9dd66c4375308874eb7def63 to your computer and use it in GitHub Desktop.
Save garrytrinder/4df2aeaf9dd66c4375308874eb7def63 to your computer and use it in GitHub Desktop.
Removes Wiki Tab from Microsoft Teams Channel
[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
Copy link

Please Garry, correct the line 14 and change $group by $groups. Thanks!!

@stjeloma
Copy link

And in line 19 change $group[0] by $groups[0] and $channel[0] by $channels[0]

@garrytrinder
Copy link
Author

Done. Thanks for pointing those out @stjeloma 👍

@garrytrinder
Copy link
Author

@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/

@stjeloma
Copy link

Excellent Garry, thanks!!

@garrytrinder
Copy link
Author

My pleasure, happy to help 😊 #SharingIsCaring

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment