blob: 288b4ee0d5c269fb6b08febc8951b57e6ebd9417 (
plain)
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
|
$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
|