Public/Get-HibpBreach.ps1
function Get-HibpBreach { <# .SYNOPSIS Gets all breaches in the system or a single breach by name. .DESCRIPTION Retrieves a list of all breaches in the Have I Been Pwned system. This can be filtered by domain or whether the breach is a spam list. Optionally, you can specify a single breach name to retrieve details for just that breach. .PARAMETER Name The name of a single breach to retrieve (e.g., "Adobe"). .PARAMETER Domain Filters the results to only breaches on a specific domain. This is only valid when retrieving all breaches. .PARAMETER IsSpamList Filters the results based on the 'IsSpamList' flag. Set to $true to only get spam lists, $false to exclude them. This is only valid when retrieving all breaches. .PARAMETER ApiKey Your HIBP API key. Can be used instead of saving the key with Save-HibpCredential. .EXAMPLE Get-HibpBreach Returns all breaches in the system. .EXAMPLE Get-HibpBreach -Domain 'adobe.com' Returns all breaches for the 'adobe.com' domain. .EXAMPLE Get-HibpBreach -Name 'Adobe' Returns the details for the Adobe breach. .LINK https://haveibeenpwned.com/API/v3#Breaches #> [CmdletBinding(DefaultParameterSetName = 'ByFilter')] Param( [Parameter(Mandatory = $true, Position = 0, ParameterSetName = 'ByName')] [string]$Name, [Parameter(ParameterSetName = 'ByFilter')] [string]$Domain, [Parameter(ParameterSetName = 'ByFilter')] [switch]$IsSpamList, [string]$ApiKey ) $queryParameter = @{} $endpoint = '' if ($PSCmdlet.ParameterSetName -eq 'ByName') { $endpoint = 'breach/{0}' -f $Name } else { # ByFilter $endpoint = 'breaches' if ($PSBoundParameters.ContainsKey('Domain')) { $queryParameter.Domain = $Domain } if ($PSBoundParameters.ContainsKey('IsSpamList')) { $queryParameter.IsSpamList = $IsSpamList.ToString().ToLower() } } $invokeParams = @{ Endpoint = $endpoint } if ($queryParameter.Count -gt 0) { $invokeParams.QueryParameter = $queryParameter } if ($PSBoundParameters.ContainsKey('ApiKey')) { $invokeParams.ApiKey = $ApiKey } Invoke-HibpRequest @invokeParams } |