diff options
Diffstat (limited to 'T2R.ps1')
| -rw-r--r-- | T2R.ps1 | 59 |
1 files changed, 59 insertions, 0 deletions
@@ -0,0 +1,59 @@ +$tenantId = "00000000-0000-0000-0000-000000000000" +$clientID = "00000000-0000-0000-0000-000000000000" +$clientSecret = (ConvertTo-SecureString "CLIENT_SECRET_VALUE" -AsPlainText -Force ) +$Scope = "https://graph.microsoft.com/.default" +$authToken = Get-MsalToken -ClientId $clientID -ClientSecret $clientSecret -TenantId $tenantId -Scopes $Scope + +$TeamsTeam = Read-Host "Enter team name" + +$Headers = @{ + "Authorization" = "Bearer $($authToken.AccessToken)" + "Content-type" = "application/json" +} + +$allTeams = @() +$aadTeams = (Invoke-RestMethod -Uri "https://graph.microsoft.com/v1.0/teams/" -Headers $Headers -Method Get -ContentType "application/json") +$allTeams += $aadTeams.value +if ($aadTeams.'@odata.nextLink') { + do { + $aadTeams = (Invoke-RestMethod -Uri $aadTeams.'@odata.nextLink' -Headers $Headers -Method Get -ContentType "application/json") + $allTeams += $aadTeams.value + } until (!$aadTeams.'@odata.nextLink') +} +$aadTeams = $allTeams + +$channels = [System.Collections.ArrayList]::New() + +foreach ($teams in $aadTeams) { + if ($teams.displayName -like "$($TeamsTeam)*") { + $apiUri = "https://graph.microsoft.com/v1.0/teams/$($teams.id)/channels" + $Team = Invoke-RestMethod -Headers $Headers -Uri $apiUri -Method GET + $channelList = $Team.Value + foreach ($channel in $channelList) { + $channelFolder = Invoke-RestMethod -Headers $Headers -Uri "https://graph.microsoft.com/v1.0/teams/$($teams.id)/channels/$($channel.id)/filesFolder" -Method GET + $DriveID = $channelFolder.parentReference.driveId + $displayName = $channelFolder.name -replace " ", "_" -replace ",", "" + $Result = [PSCustomObject]@{ + displayName = $displayName + driveID = $DriveID + membershipType = $channel.membershipType + teamName = $teams.displayName + } + [void]$channels.Add($Result) + } + } +} + +$uniqueDrives = $channels | Sort-Object -Property driveID -Unique | Select-Object displayName, driveID, membershipType, teamName +$uniqueDrives | ForEach-Object { if ($_.membershipType -eq 'standard') { $_.displayName = $_.teamName -replace " ", "_" } } +foreach ($drive in $uniqueDrives) { + $config = Get-Content -Path ./remote-template.conf -Raw + $remote = $config -f $drive.displayName, $drive.driveID + Add-Content -Value $remote -Path ./rclone.conf +} + +$teamNames = $($uniqueDrives.displayName -join [Environment]::NewLine) -replace "\n", ": " +$teamNames = $teamNames + ":" +$union = Get-Content -Path ./union-template.conf -Raw +$unionConf = $union -f "$($channels[0].teamName)_union", $teamNames +Add-Content -Value $unionConf -Path ./rclone.conf
\ No newline at end of file |
