From 55fb519f4301a5846387dd2ba228bf6d41dee6e4 Mon Sep 17 00:00:00 2001 From: AK Date: Tue, 26 May 2026 12:07:09 +0530 Subject: [PATCH] Support Metadata.json body for PIM schedule request --- Metadata.json | 18 ++++++++++++++++++ entra-pim-self-activate.ps1 | 38 ++++++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 15 deletions(-) create mode 100644 Metadata.json diff --git a/Metadata.json b/Metadata.json new file mode 100644 index 0000000000..81ead332fe --- /dev/null +++ b/Metadata.json @@ -0,0 +1,18 @@ +{ + "action": "selfActivate", + "principalId": "11111111-1111-1111-1111-111111111111", + "roleDefinitionId": "8424c6f0-a189-499e-bbd0-26c1753c96d4", + "directoryScopeId": "/", + "justification": "Activation requested from metadata.json", + "scheduleInfo": { + "startDateTime": "2026-05-26T00:00:00Z", + "expiration": { + "type": "AfterDuration", + "duration": "PT5H" + } + }, + "ticketInfo": { + "ticketNumber": "AKHIL-ATTR-0001", + "ticketSystem": "QIH3B" + } +} diff --git a/entra-pim-self-activate.ps1 b/entra-pim-self-activate.ps1 index 3820f73ae6..c8b47d9308 100644 --- a/entra-pim-self-activate.ps1 +++ b/entra-pim-self-activate.ps1 @@ -478,22 +478,30 @@ catch { Write-Host "`n[5/6] Submitting self-activation request..." -ForegroundColor Cyan -$params = @{ - action = "selfActivate" - principalId = $principalId - roleDefinitionId = $Config.RoleDefinitionId - directoryScopeId = $Config.DirectoryScopeId - justification = $Config.Justification - scheduleInfo = @{ - startDateTime = Get-Date - expiration = @{ - type = "AfterDuration" - duration = $Config.Duration +$metadataPath = Join-Path -Path (Get-Location) -ChildPath "Metadata.json" + +if (Test-Path -Path $metadataPath) { + Write-Host " Found Metadata.json. Using JSON body for request." -ForegroundColor DarkGray + $params = Get-Content -Raw -Path $metadataPath | ConvertFrom-Json -AsHashtable +} +else { + $params = @{ + action = "selfActivate" + principalId = $principalId + roleDefinitionId = $Config.RoleDefinitionId + directoryScopeId = $Config.DirectoryScopeId + justification = $Config.Justification + scheduleInfo = @{ + startDateTime = Get-Date + expiration = @{ + type = "AfterDuration" + duration = $Config.Duration + } + } + ticketInfo = @{ + ticketNumber = $Config.TicketNumber + ticketSystem = $Config.TicketSystem } - } - ticketInfo = @{ - ticketNumber = $Config.TicketNumber - ticketSystem = $Config.TicketSystem } }