Posh-Postcodes.io

Posh-postcodes.io is a PowerShell module that leverages the Postcodes.io API used for working with UK postcode data

Note

Postcodes.io is an open sourced project maintained by Ideal Postcodes. It is a free resource, allowing developers to search, reverse geocode and extract UK postcode and associated data.

Functions

The following functions are included in this module.

Name Description
Get-MatchingPostcode Submit a postcode query and receive a complete list of postcode matches and all associated postcode data.
Get-NearestOutwardCode Returns nearest outcodes for a given longitude and latitude or a given Outcode
Get-NearestPostcode Returns nearest postcodes for a given longitude and latitude, or a given postcode.
Get-OutwardCode Geolocation data for the centroid of the outward code specified.
Get-PostcodeInfo Returns a single postcode entity for a given postcode.
Get-RandomPostcode Returns a random postcode and all available data for that postcode.
Test-Postcode Convenience method to validate a postcode.

Example Usage

Install and Import the module

The module can be installed from the PowerShell Gallery

1Install-Module Posh-Postcodes.io 
1Import-Module Posh-Postcodes.io

Lookup a Postcode

The following example will return information associated with the postcode L4 0TH.

 1Get-PostcodeInfo -Postcode 'L4 0TH'
 2
 3postcode                        : L4 0TH
 4quality                         : 1
 5eastings                        : 336209
 6northings                       : 393151
 7country                         : England
 8nhs_ha                          : North West
 9longitude                       : -2.961584
10latitude                        : 53.431267
11european_electoral_region       : North West
12primary_care_trust              : Liverpool
13region                          : North West
14lsoa                            : Liverpool 018A
15msoa                            : Liverpool 018
16incode                          : 0TH
17outcode                         : L4
18parliamentary_constituency      : Liverpool, Walton
19parliamentary_constituency_2024 : Liverpool Riverside
20admin_district                  : Liverpool
21parish                          : Liverpool, unparished area
22admin_county                    :
23date_of_introduction            : 198001
24admin_ward                      : Anfield
25ced                             :
26ccg                             : NHS Cheshire and Merseyside
27nuts                            : Liverpool
28pfa                             : Merseyside
29codes                           : @{admin_district=E08000012;
30                                    admin_county=E99999999; 
31                                    admin_ward=E05015279;
32                                    parish=E43000166;
33                                    parliamentary_constituency=E14000794;
34                                    parliamentary_constituency_2024=E14001338;
35                                    ccg=E38000101;
36                                    ccg_id=99A;
37                                    ced=E99999999;
38                                    nuts=TLD72;
39                                    lsoa=E01006542;
40                                    msoa=E02001364;
41                                    lau2=E08000012;
42                                    pfa=E23000004}

Random Postcodes

In this example the module is used to randomly select 10 postcodes that start SW19 and display the postcode along with the parliamentary constituency for that location.

11..10 | ForEach-Object { 
2            Get-RandomPostcode -Outcode 'SW19' | 
3            Select-Object postcode, parliamentary_constituency
4        }

The output will look something like this.

 1postcode parliamentary_constituency
 2-------- --------------------------
 3SW19 8RA Wimbledon
 4SW19 2DE Mitcham and Morden
 5SW19 6EX Putney
 6SW19 8LT Wimbledon
 7SW19 3LL Wimbledon
 8SW19 7BW Wimbledon
 9SW19 7JF Wimbledon
10SW19 4UH Wimbledon
11SW19 2RG Mitcham and Morden
12SW19 1LN Wimbledon

Get-Help

Full descriptions and examples are available through Get-Help, for example

1Get-Help Get-PostcodeInfo -Examples
2Get-Help Test-Postcode
3Get-Help Get-NearestPostcode -ShowWindow