Create_Teams.csv
1 2 3 |
TeamsName,MailNickname,TeamType,ChannelName,Owners,Members NL 03 PROJECTS Private,NL03PROJECTSPrivate,Private,E 664 Wageningen Plus Ultra II;E 691 Plus Ultra Groningen,admin@werkindecloud.onmicrosoft.com,iris@werkinde.cloud;Switch@werkinde.cloud;demo@werkinde.cloud;test@werkinde.cloud |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
function Create-Channel { param ( $ChannelName,$GroupId,$MembershipType ) Process { try { $teamchannels = $ChannelName -split ";" if($teamchannels) { for($i =0; $i -le ($teamchannels.count - 1) ; $i++) { New-TeamChannel -GroupId $GroupId -DisplayName $teamchannels[$i] -MembershipType $MembershipType } } } Catch { } } } function Add-Users { param( $Users,$GroupId,$CurrentUsername,$Role ) Process { try{ $teamusers = $Users -split ";" if($teamusers) { for($j =0; $j -le ($teamusers.count - 1) ; $j++) { if($teamusers[$j] -ne $CurrentUsername) { Add-TeamUser -GroupId $GroupId -User $teamusers[$j] -Role $Role } } } } Catch { } } } function Create-NewTeam { param ( $ImportPath ) Process { #Import-Module MicrosoftTeams #$cred = Get-Credential #$username = $cred.UserName #Connect-MicrosoftTeams $teams = Import-Csv -Path $ImportPath foreach($team in $teams) { $getteam= get-team |where-object { $_.displayname -eq $team.TeamsName} If($getteam -eq $null) { Write-Host "Start creating the team: " $team.TeamsName $group = New-Team -MailNickname $team.MailNickname -displayname $team.TeamsName -Visibility $team.TeamType -AllowCreateUpdateChannels $False -AllowDeleteChannels $False -AllowAddRemoveApps $False -AllowCreateUpdateRemoveTabs $False -AllowCreateUpdateRemoveConnectors $False Write-Host "Creating channels..." Create-Channel -ChannelName $team.ChannelName -GroupId $group.GroupId -MembershipType Private Write-Host "Adding team members..." Add-Users -Users $team.Members -GroupId $group.GroupId -CurrentUsername $username -Role Member Write-Host "Adding team owners..." Add-Users -Users $team.Owners -GroupId $group.GroupId -CurrentUsername $username -Role Owner Write-Host "Completed creating the team: " $team.TeamsName $team=$null } } } } Create-NewTeam -ImportPath "C:\365\Team01.csv" |
Export Group ID. Let op opnieuw verbinding maken.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
$AllTeams = (Get-Team).GroupID $TeamList = @() Foreach ($Team in $AllTeams) { $TeamGUID = $Team.ToString() $TeamName = (Get-Team | ?{$_.GroupID -eq $Team}).DisplayName $TeamOwner = (Get-TeamUser -GroupId $Team | ?{$_.Role -eq 'Owner'}).Name $TeamMember = (Get-TeamUser -GroupId $Team | ?{$_.Role -eq 'Member'}).Name $TeamList = $TeamList + [PSCustomObject]@{TeamName = $TeamName; TeamObjectID = $TeamGUID; TeamOwners = $TeamOwner -join ', '; TeamMembers = $TeamMember -join ', '} } $TeamList | export-csv c:\temp\TeamsData.csv -NoTypeInformation |
1 2 |
Import-Csv C:\Temp\TeamsData.csv | ForEach-Object { Set-Team -GroupId $_.TeamObjectID -AllowCreateUpdateChannels $False -AllowDeleteChannels $False -AllowAddRemoveApps $False -AllowCreateUpdateRemoveTabs $False -AllowCreateUpdateRemoveConnectors $False} |
RemoveWiki.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
#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 = "XXX" $tenantId = "XXX" $clientSecret = "XXX" # 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" } } } } } |
API permissions
Group.ReadWrite.All | Delegated |
Group.ReadWrite.All | Application |