forked from FH-Inway/Yammer-Archiver
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdate-LatestMessageId.ps1
More file actions
39 lines (34 loc) · 1.57 KB
/
Copy pathUpdate-LatestMessageId.ps1
File metadata and controls
39 lines (34 loc) · 1.57 KB
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
# Update-LatestMessageId.ps1
# Updates groups-config.json with the latest message id for each group
$repoRoot = Split-Path -Parent $MyInvocation.MyCommand.Path
$configPath = Join-Path $repoRoot 'Dynamics 365 and Power Platform Preview Programs\groups-config.json'
# Load the group config
$config = Get-Content $configPath | ConvertFrom-Json
foreach ($group in $config.groups) {
$groupName = $group.name
Write-Host "Processing group: $groupName"
$groupDir = Join-Path $repoRoot "Dynamics 365 and Power Platform Preview Programs\$groupName"
if (Test-Path $groupDir) {
$jsonFiles = Get-ChildItem -Path $groupDir -Filter "*Messages*.json" -File
$maxId = 0
foreach ($jsonFile in $jsonFiles) {
$json = Get-Content $jsonFile.FullName -Raw | ConvertFrom-Json
if ($json.body.value) {
$ids = $json.body.value | Where-Object { $_.id } | ForEach-Object { [int64]$_.id }
if ($ids.Count -gt 0) {
$fileMax = ($ids | Measure-Object -Maximum).Maximum
if ($fileMax -gt $maxId) { $maxId = $fileMax }
}
}
}
$group.lastMessageId = $maxId
} else {
$group.lastMessageId = 0
}
}
# Save the updated config with integer lastMessageId values
$json = $config | ConvertTo-Json -Depth 5
# Replace any ".0" at the end of lastMessageId values with nothing
$json = $json -replace '("lastMessageId"\s*:\s*)(\d+)\.0', '$1$2'
$json | Set-Content $configPath -Encoding UTF8
Write-Host "groups-config.json updated with latest message ids."