Private/Assert-NSPEntraAddressCloudState.ps1
|
function Assert-NSPEntraAddressCloudState { [CmdletBinding()] param([Parameter(Mandatory)]$Queue,[Parameter(Mandatory)][object[]]$Plan) Import-NSPM365Graph Assert-NSPEntraPairingSession -Purpose Preflight -TenantId $Queue.tenantId Assert-NSPEntraPairingTenant -ExpectedTenantId $Queue.tenantId | Out-Null foreach ($entry in $Plan) { $before = $entry.CloudBefore if (-not $before.ObjectId) { throw 'Reviewed cloud identity is missing; regenerate the plan.' } $fresh = Invoke-NSPGraphRequest -Uri ("users/{0}?`$select=id,userPrincipalName,mail,proxyAddresses" -f [uri]::EscapeDataString($before.ObjectId)) if (-not $fresh -or $null -eq $fresh.proxyAddresses -or [string]$fresh.id -cne [string]$before.ObjectId -or [string]$fresh.userPrincipalName -cne [string]$before.UserPrincipalName -or [string]$fresh.mail -cne [string]$before.Mail) { throw 'Cloud address state changed or is unreadable. Refresh inventories and review before AD apply.' } $old = ConvertTo-Json -InputObject @($before.ProxyAddresses | Sort-Object -CaseSensitive) -Compress $new = ConvertTo-Json -InputObject @($fresh.proxyAddresses | Sort-Object -CaseSensitive) -Compress if ($old -cne $new) { throw 'Cloud proxy addresses changed. Refresh inventories and review before AD apply.' } } } |