Public/Get-PDHostedSPF.ps1
|
function Get-PDHostedSPF { <# .SYNOPSIS Retrieves the Hosted SPF (PowerSPF) configuration for one or more PowerDMARC domains. .DESCRIPTION Calls the PowerDMARC Hosted SPF API for each domain ID and returns the SPF mechanisms PowerDMARC is currently hosting/flattening on that domain's behalf. Requires an active connection created with Connect-PowerDMARC. Behavior depends on the mode (and root URI) stored by Connect-PowerDMARC: - Default mode (root /api/v1): `GET /hostedspf/{domainId}` - Reseller mode (root /api/v1/mssp): `GET /hosted/spf/{domainId}` .PARAMETER DomainId The PowerDMARC domain ID(s) to retrieve the Hosted SPF configuration for. Accepts pipeline input, including by property name (e.g. piped from Get-PDDomain). Defaults to the domain selected via Select-PDDomain, if any. .PARAMETER EnabledOnly Only return entries where is_enabled is true. .EXAMPLE Get-PDHostedSPF -DomainId 12345 .EXAMPLE 12345, 67890 | Get-PDHostedSPF .EXAMPLE Get-PDDomain | Get-PDHostedSPF .EXAMPLE Select-PDDomain -DomainId 12345 Get-PDHostedSPF .LINK https://api.powerdmarc.com/api/end-user/api-v-1-documentation .LINK https://api.powerdmarc.com/api/mssp/api-v-1-documentation #> [CmdletBinding()] [OutputType([pscustomobject])] param( [Parameter(Position = 0, ValueFromPipeline, ValueFromPipelineByPropertyName)] [Alias('Id')] [int[]]$DomainId, [Parameter()] [switch]$EnabledOnly ) begin { $ctx = Get-PDRequestContext } process { $ids = if ($PSBoundParameters.ContainsKey('DomainId')) { $DomainId } elseif ($ctx.DomainId) { @($ctx.DomainId) } else { $null } if (-not $ids) { throw 'DomainId is required. Pass -DomainId, or set a default with Select-PDDomain.' } foreach ($id in $ids) { $uri = if ($ctx.Mode -eq 'Reseller') { "$($ctx.BaseUri)/hosted/spf/$id" } else { "$($ctx.BaseUri)/hostedspf/$id" } try { $response = Invoke-RestMethod -Uri $uri -Headers $ctx.Headers -Method Get -ErrorAction Stop } catch { Write-Error "Failed to retrieve Hosted SPF for domain ID $id`: $($_.Exception.Message)" continue } foreach ($record in $response.data) { if ($EnabledOnly -and -not $record.is_enabled) { continue } $record | Add-Member -NotePropertyName 'DomainId' -NotePropertyValue $id -Force $null = Set-PDTypeName -InputObject $record.spf_labels -TypeName 'PowerDMARC.SpfLabels' Set-PDTypeName -InputObject $record -TypeName 'PowerDMARC.HostedSPF' } } } } |