Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@stjeloma stjeloma commented Jul 23, 2020

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

@stjeloma

This comment has been minimized.

Copy link

@stjeloma stjeloma commented Jul 23, 2020

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

@garrytrinder

This comment has been minimized.

Copy link
Owner Author

@garrytrinder garrytrinder commented Jul 23, 2020

Done. Thanks for pointing those out @stjeloma 👍

@garrytrinder

This comment has been minimized.

Copy link
Owner Author

@garrytrinder garrytrinder commented Jul 23, 2020

@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

This comment has been minimized.

Copy link

@stjeloma stjeloma commented Jul 23, 2020

Excellent Garry, thanks!!

@garrytrinder

This comment has been minimized.

Copy link
Owner Author

@garrytrinder garrytrinder commented Jul 23, 2020

My pleasure, happy to help 😊 #SharingIsCaring

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