Skip to content

Instantly share code, notes, and snippets.

@AlexanderHolmeset-zz
Created May 10, 2019 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexanderHolmeset-zz/e40c7e9297ae9cc01cb832871a9ff770 to your computer and use it in GitHub Desktop.
Save AlexanderHolmeset-zz/e40c7e9297ae9cc01cb832871a9ff770 to your computer and use it in GitHub Desktop.
#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"
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment