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

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