Private/Get-PDRequestContext.ps1
|
function Get-PDRequestContext { <# .SYNOPSIS Returns the stored PowerDMARC connection as ready-to-use request context (internal helper). .DESCRIPTION Reads the connection stored by Connect-PowerDMARC ($script:PDConnection), converts the stored SecureString API token into a Bearer Authorization header, and returns the base URI, mode (Default/Reseller), default Reseller AccountId, default DomainId and headers together so Public cmdlets don't have to repeat that logic. #> [CmdletBinding()] [OutputType([pscustomobject])] param() if (-not $script:PDConnection) { throw 'Not connected to PowerDMARC. Run Connect-PowerDMARC first.' } $plainToken = [System.Net.NetworkCredential]::new('', $script:PDConnection.ApiToken).Password [pscustomobject]@{ BaseUri = $script:PDConnection.BaseUri Mode = $script:PDConnection.Mode AccountId = $script:PDConnection.AccountId DomainId = $script:PDConnection.DomainId Headers = @{ Authorization = "Bearer $plainToken" Accept = 'application/json' } } } |