Seed-Offerings.ps1: JSON-array expliciet opsommen (PowerShell 5.1)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-12 10:09:41 +01:00
co-authored by Claude Sonnet 5.5
parent b94245fc12
commit 6349d99f16
+5 -2
View File
@@ -73,7 +73,9 @@ finally {
$headers = @{ Authorization = "Bearer $($login.accessToken)" }
# The public list tells which slugs exist already.
$existing = @(Invoke-RestMethod -Method Get -Uri "$api/offerings" -Headers $headers | ForEach-Object { $_.slug })
# Windows PowerShell 5.1 hands a JSON array over as ONE object; wrap it so every item is enumerated.
$list = @(Invoke-RestMethod -Method Get -Uri "$api/offerings" -Headers $headers)
$existing = @(foreach ($o in $list) { $o.slug })
foreach ($p in $packages) {
if ($existing -contains $p.slug) { Write-Host "skip $($p.slug) (exists)"; continue }
@@ -98,4 +100,5 @@ foreach ($p in $packages) {
}
Write-Host 'Result:'
Invoke-RestMethod -Method Get -Uri "$api/offerings" | ForEach-Object { Write-Host (" {0,2} {1} {2} [{3}]" -f $_.displayOrder, $_.slug, $_.price, $_.layout) }
$final = @(Invoke-RestMethod -Method Get -Uri "$api/offerings")
foreach ($o in $final) { Write-Host (" {0,2} {1} {2} [{3}]" -f $o.displayOrder, $o.slug, $o.price, $o.layout) }