Skip to content

Instantly share code, notes, and snippets.

@JohnLBevan
Last active April 16, 2021 14:38
Show Gist options
  • Select an option

  • Save JohnLBevan/29f3e9bf32e98c4b02e115910a8d162a to your computer and use it in GitHub Desktop.

Select an option

Save JohnLBevan/29f3e9bf32e98c4b02e115910a8d162a to your computer and use it in GitHub Desktop.
ISO 3166 Country Codes. Data pulled from Wikipedia / hacky PowerShell script used to grab data included
clear-host
$data = Invoke-RestMethod -Method Get -Uri 'https://en.wikipedia.org/wiki/List_of_ISO_3166_country_codes'
$a = $data.SelectNodes('//*[local-name() = ''table''][./@class=''wikitable sortable'']//*[local-name() = ''tbody'']//*[local-name() = ''tr''][./*[local-name() = ''td'']]') | %{
[pscustomobject]@{
Name = $_.SelectSingleNode('(./*[local-name() = ''td''][1])[1]').InnerText -replace '^\s+','' -replace '\s+$',''
FullName = $_.SelectSingleNode('(./*[local-name() = ''td''][2])[1]').InnerText -replace '^\s+','' -replace '\s+$',''
Alpha2 = $_.SelectSingleNode('(./*[local-name() = ''td''][4])[1]').InnerText -replace '^\s+','' -replace '\s+$',''
Alpha3 = $_.SelectSingleNode('(./*[local-name() = ''td''][5])[1]').InnerText -replace '^\s+','' -replace '\s+$',''
Num = $_.SelectSingleNode('(./*[local-name() = ''td''][6])[1]').InnerText -replace '^\s+','' -replace '\s+$',''
}
}
#very basic/hacky cleansing
$a = $a `
| ?{$_.Name -notlike '* – Please see *'} `
| %{$_.Name = $_.Name -replace '\u200a.*$',''; $_} `
| %{$_.Alpha2 = $_.Alpha2 -replace [Regex]::Escape('.mw-parser-output .monospaced{font-family:monospace,monospace}'),''; $_}
#output results (on screen)
$a | Select-Object Alpha2, Alpha3, Num, Name, FullName | ConvertTo-Csv -NoTypeInformation
Alpha2 Alpha3 Num Name FullName
AF AFG 004 Afghanistan The Islamic Republic of Afghanistan
AX ALA 248 Åland Islands Åland
AL ALB 008 Albania The Republic of Albania
DZ DZA 012 Algeria The People's Democratic Republic of Algeria
AS ASM 016 American Samoa The Territory of American Samoa
AD AND 020 Andorra The Principality of Andorra
AO AGO 024 Angola The Republic of Angola
AI AIA 660 Anguilla Anguilla
AQ ATA 010 Antarctica All land and ice shelves south of the 60th parallel south
AG ATG 028 Antigua and Barbuda Antigua and Barbuda
AR ARG 032 Argentina The Argentine Republic
AM ARM 051 Armenia The Republic of Armenia
AW ABW 533 Aruba Aruba
AU AUS 036 Australia The Commonwealth of Australia
AT AUT 040 Austria The Republic of Austria
AZ AZE 031 Azerbaijan The Republic of Azerbaijan
BS BHS 044 Bahamas, The The Commonwealth of The Bahamas
BH BHR 048 Bahrain The Kingdom of Bahrain
BD BGD 050 Bangladesh The People's Republic of Bangladesh
BB BRB 052 Barbados Barbados
BY BLR 112 Belarus The Republic of Belarus
BE BEL 056 Belgium The Kingdom of Belgium
BZ BLZ 084 Belize Belize
BJ BEN 204 Benin The Republic of Benin
BM BMU 060 Bermuda Bermuda
BT BTN 064 Bhutan The Kingdom of Bhutan
BO BOL 068 Bolivia, Plurinational State of The Plurinational State of Bolivia
BQ BES 535 Bonaire Sint Eustatius Saba Bonaire, Sint Eustatius and Saba
BA BIH 070 Bosnia and Herzegovina Bosnia and Herzegovina
BW BWA 072 Botswana The Republic of Botswana
BV BVT 074 Bouvet Island Bouvet Island
BR BRA 076 Brazil The Federative Republic of Brazil
IO IOT 086 British Indian Ocean Territory, The The British Indian Ocean Territory
BN BRN 096 Brunei Darussalam The Nation of Brunei, the Abode of Peace
BG BGR 100 Bulgaria The Republic of Bulgaria
BF BFA 854 Burkina Faso Burkina Faso
BI BDI 108 Burundi The Republic of Burundi
CV CPV 132 Cabo Verde The Republic of Cabo Verde
KH KHM 116 Cambodia The Kingdom of Cambodia
CM CMR 120 Cameroon The Republic of Cameroon
CA CAN 124 Canada Canada
KY CYM 136 Cayman Islands, The The Cayman Islands
CF CAF 140 Central African Republic, The The Central African Republic
TD TCD 148 Chad The Republic of Chad
CL CHL 152 Chile The Republic of Chile
CN CHN 156 China The People's Republic of China
CX CXR 162 Christmas Island The Territory of Christmas Island
CC CCK 166 Cocos (Keeling) Islands, The The Territory of Cocos (Keeling) Islands
CO COL 170 Colombia The Republic of Colombia
KM COM 174 Comoros, The The Union of the Comoros
CD COD 180 Congo, The Democratic Republic of the The Democratic Republic of the Congo
CG COG 178 Congo, The The Republic of the Congo
CK COK 184 Cook Islands, The The Cook Islands
CR CRI 188 Costa Rica The Republic of Costa Rica
CI CIV 384 Côte d'Ivoire The Republic of Côte d'Ivoire
HR HRV 191 Croatia The Republic of Croatia
CU CUB 192 Cuba The Republic of Cuba
CW CUW 531 Curaçao The Country of Curaçao
CY CYP 196 Cyprus The Republic of Cyprus
CZ CZE 203 Czechia The Czech Republic
DK DNK 208 Denmark The Kingdom of Denmark
DJ DJI 262 Djibouti The Republic of Djibouti
DM DMA 212 Dominica The Commonwealth of Dominica
DO DOM 214 Dominican Republic, The The Dominican Republic
EC ECU 218 Ecuador The Republic of Ecuador
EG EGY 818 Egypt The Arab Republic of Egypt
SV SLV 222 El Salvador The Republic of El Salvador
GQ GNQ 226 Equatorial Guinea The Republic of Equatorial Guinea
ER ERI 232 Eritrea The State of Eritrea
EE EST 233 Estonia The Republic of Estonia
SZ SWZ 748 Eswatini The Kingdom of Eswatini
ET ETH 231 Ethiopia The Federal Democratic Republic of Ethiopia
FK FLK 238 Falkland Islands, The [Malvinas] The Falkland Islands
FO FRO 234 Faroe Islands, The The Faroe Islands
FJ FJI 242 Fiji The Republic of Fiji
FI FIN 246 Finland The Republic of Finland
FR FRA 250 France The French Republic
GF GUF 254 French Guiana Guyane
PF PYF 258 French Polynesia French Polynesia
TF ATF 260 French Southern Territories, The The French Southern and Antarctic Lands
GA GAB 266 Gabon The Gabonese Republic
GM GMB 270 Gambia, The The Republic of The Gambia
GE GEO 268 Georgia Georgia
DE DEU 276 Germany The Federal Republic of Germany
GH GHA 288 Ghana The Republic of Ghana
GI GIB 292 Gibraltar Gibraltar
GR GRC 300 Greece The Hellenic Republic
GL GRL 304 Greenland Kalaallit Nunaat
GD GRD 308 Grenada Grenada
GP GLP 312 Guadeloupe Guadeloupe
GU GUM 316 Guam The Territory of Guam
GT GTM 320 Guatemala The Republic of Guatemala
GG GGY 831 Guernsey The Bailiwick of Guernsey
GN GIN 324 Guinea The Republic of Guinea
GW GNB 624 Guinea-Bissau The Republic of Guinea-Bissau
GY GUY 328 Guyana The Co-operative Republic of Guyana
HT HTI 332 Haiti The Republic of Haiti
HM HMD 334 Heard Island and McDonald Islands The Territory of Heard Island and McDonald Islands
VA VAT 336 Holy See, The The Holy See
HN HND 340 Honduras The Republic of Honduras
HK HKG 344 Hong Kong The Hong Kong Special Administrative Region
HU HUN 348 Hungary Hungary
IS ISL 352 Iceland Iceland
IN IND 356 India The Republic of India
ID IDN 360 Indonesia The Republic of Indonesia
IR IRN 364 Iran, Islamic Republic of The Islamic Republic of Iran
IQ IRQ 368 Iraq The Republic of Iraq
IE IRL 372 Ireland Ireland
IM IMN 833 Isle of Man The Isle of Man
IL ISR 376 Israel The State of Israel
IT ITA 380 Italy The Italian Republic
JM JAM 388 Jamaica Jamaica
JP JPN 392 Japan Japan
JE JEY 832 Jersey The Bailiwick of Jersey
JO JOR 400 Jordan The Hashemite Kingdom of Jordan
KZ KAZ 398 Kazakhstan The Republic of Kazakhstan
KE KEN 404 Kenya The Republic of Kenya
KI KIR 296 Kiribati The Republic of Kiribati
KP PRK 408 Korea, The Democratic People's Republic of The Democratic People's Republic of Korea
KR KOR 410 Korea, The Republic of The Republic of Korea
KW KWT 414 Kuwait The State of Kuwait
KG KGZ 417 Kyrgyzstan The Kyrgyz Republic
LA LAO 418 Lao People's Democratic Republic, The The Lao People's Democratic Republic
LV LVA 428 Latvia The Republic of Latvia
LB LBN 422 Lebanon The Lebanese Republic
LS LSO 426 Lesotho The Kingdom of Lesotho
LR LBR 430 Liberia The Republic of Liberia
LY LBY 434 Libya The State of Libya
LI LIE 438 Liechtenstein The Principality of Liechtenstein
LT LTU 440 Lithuania The Republic of Lithuania
LU LUX 442 Luxembourg The Grand Duchy of Luxembourg
MO MAC 446 Macao The Macau Special Administrative Region
MK MKD 807 Macedonia, The former Yugoslav Republic of The Republic of Macedonia
MG MDG 450 Madagascar The Republic of Madagascar
MW MWI 454 Malawi The Republic of Malawi
MY MYS 458 Malaysia Malaysia
MV MDV 462 Maldives The Republic of Maldives
ML MLI 466 Mali The Republic of Mali
MT MLT 470 Malta The Republic of Malta
MH MHL 584 Marshall Islands, The The Republic of the Marshall Islands
MQ MTQ 474 Martinique Martinique
MR MRT 478 Mauritania The Islamic Republic of Mauritania
MU MUS 480 Mauritius The Republic of Mauritius
YT MYT 175 Mayotte The Department of Mayotte
MX MEX 484 Mexico The United Mexican States
FM FSM 583 Micronesia, Federated States of The Federated States of Micronesia
MD MDA 498 Moldova, The Republic of The Republic of Moldova
MC MCO 492 Monaco The Principality of Monaco
MN MNG 496 Mongolia The State of Mongolia
ME MNE 499 Montenegro Montenegro
MS MSR 500 Montserrat Montserrat
MA MAR 504 Morocco The Kingdom of Morocco
MZ MOZ 508 Mozambique The Republic of Mozambique
MM MMR 104 Myanmar The Republic of the Union of Myanmar
NA NAM 516 Namibia The Republic of Namibia
NR NRU 520 Nauru The Republic of Nauru
NP NPL 524 Nepal The Federal Democratic Republic of Nepal
NL NLD 528 Netherlands, The The Kingdom of the Netherlands
NC NCL 540 New Caledonia New Caledonia
NZ NZL 554 New Zealand New Zealand
NI NIC 558 Nicaragua The Republic of Nicaragua
NE NER 562 Niger, The The Republic of the Niger
NG NGA 566 Nigeria The Federal Republic of Nigeria
NU NIU 570 Niue Niue
NF NFK 574 Norfolk Island The Territory of Norfolk Island
MP MNP 580 Northern Mariana Islands, The The Commonwealth of the Northern Mariana Islands
NO NOR 578 Norway The Kingdom of Norway
OM OMN 512 Oman The Sultanate of Oman
PK PAK 586 Pakistan The Islamic Republic of Pakistan
PW PLW 585 Palau The Republic of Palau
PS PSE 275 Palestine, State of The State of Palestine
PA PAN 591 Panama The Republic of Panamá
PG PNG 598 Papua New Guinea The Independent State of Papua New Guinea
PY PRY 600 Paraguay The Republic of Paraguay
PE PER 604 Peru The Republic of Perú
PH PHL 608 Philippines, The The Republic of the Philippines
PN PCN 612 Pitcairn The Pitcairn, Henderson, Ducie and Oeno Islands
PL POL 616 Poland The Republic of Poland
PT PRT 620 Portugal The Portuguese Republic
PR PRI 630 Puerto Rico The Commonwealth of Puerto Rico
QA QAT 634 Qatar The State of Qatar
RE REU 638 Réunion Réunion
RO ROU 642 Romania Romania
RU RUS 643 Russian Federation, The The Russian Federation
RW RWA 646 Rwanda The Republic of Rwanda
BL BLM 652 Saint Barthélemy The Collectivity of Saint-Barthélemy
SH SHN 654 Saint Helena, Ascension and Tristan da Cunha Saint Helena, Ascension and Tristan da Cunha
KN KNA 659 Saint Kitts and Nevis Saint Kitts and Nevis
LC LCA 662 Saint Lucia Saint Lucia
MF MAF 663 Saint Martin (French part) The Collectivity of Saint-Martin
PM SPM 666 Saint Pierre and Miquelon The Overseas Collectivity of Saint-Pierre and Miquelon
VC VCT 670 Saint Vincent and the Grenadines Saint Vincent and the Grenadines
WS WSM 882 Samoa The Independent State of Samoa
SM SMR 674 San Marino The Republic of San Marino
ST STP 678 Sao Tome and Principe The Democratic Republic of São Tomé and Príncipe
SA SAU 682 Saudi Arabia The Kingdom of Saudi Arabia
SN SEN 686 Senegal The Republic of Senegal
RS SRB 688 Serbia The Republic of Serbia
SC SYC 690 Seychelles The Republic of Seychelles
SL SLE 694 Sierra Leone The Republic of Sierra Leone
SG SGP 702 Singapore The Republic of Singapore
SX SXM 534 Sint Maarten (Dutch part) Sint Maarten
SK SVK 703 Slovakia The Slovak Republic
SI SVN 705 Slovenia The Republic of Slovenia
SB SLB 090 Solomon Islands The Solomon Islands
SO SOM 706 Somalia The Federal Republic of Somalia
ZA ZAF 710 South Africa The Republic of South Africa
GS SGS 239 South Georgia and the South Sandwich Islands South Georgia and the South Sandwich Islands
SS SSD 728 South Sudan The Republic of South Sudan
ES ESP 724 Spain The Kingdom of Spain
LK LKA 144 Sri Lanka The Democratic Socialist Republic of Sri Lanka
SD SDN 729 Sudan, The The Republic of the Sudan
SR SUR 740 Suriname The Republic of Suriname
SJ SJM 744 Svalbard Jan Mayen Svalbard and Jan Mayen
SE SWE 752 Sweden The Kingdom of Sweden
CH CHE 756 Switzerland The Swiss Confederation
SY SYR 760 Syrian Arab Republic The Syrian Arab Republic
TW TWN 158 Taiwan (Province of China) The Republic of China
TJ TJK 762 Tajikistan The Republic of Tajikistan
TZ TZA 834 Tanzania, United Republic of The United Republic of Tanzania
TH THA 764 Thailand The Kingdom of Thailand
TL TLS 626 Timor-Leste The Democratic Republic of Timor-Leste
TG TGO 768 Togo The Togolese Republic
TK TKL 772 Tokelau Tokelau
TO TON 776 Tonga The Kingdom of Tonga
TT TTO 780 Trinidad and Tobago The Republic of Trinidad and Tobago
TN TUN 788 Tunisia The Republic of Tunisia
TR TUR 792 Turkey The Republic of Turkey
TM TKM 795 Turkmenistan Turkmenistan
TC TCA 796 Turks and Caicos Islands, The The Turks and Caicos Islands
TV TUV 798 Tuvalu Tuvalu
UG UGA 800 Uganda The Republic of Uganda
UA UKR 804 Ukraine Ukraine
AE ARE 784 United Arab Emirates, The The United Arab Emirates
GB GBR 826 United Kingdom of Great Britain and Northern Ireland, The The United Kingdom of Great Britain and Northern Ireland
UM UMI 581 United States Minor Outlying Islands, The Baker Island, Howland Island, Jarvis Island, Johnston Atoll, Kingman Reef, Midway Atoll, Navassa Island, Palmyra Atoll, and Wake Island
US USA 840 United States of America, The The United States of America
UY URY 858 Uruguay The Oriental Republic of Uruguay
UZ UZB 860 Uzbekistan The Republic of Uzbekistan
VU VUT 548 Vanuatu The Republic of Vanuatu
VE VEN 862 Venezuela, Bolivarian Republic of The Bolivarian Republic of Venezuela
VN VNM 704 Viet Nam The Socialist Republic of Viet Nam
VG VGB 092 Virgin Islands (British) The Virgin Islands
VI VIR 850 Virgin Islands (U.S.) The Virgin Islands of the United States
WF WLF 876 Wallis and Futuna The Territory of the Wallis and Futuna Islands
EH ESH 732 Western Sahara The Sahrawi Arab Democratic Republic
YE YEM 887 Yemen The Republic of Yemen
ZM ZMB 894 Zambia The Republic of Zambia
ZW ZWE 716 Zimbabwe The Republic of Zimbabwe
@JohnLBevan

Copy link
Copy Markdown
Author

For anyone hitting this looking for a way to get these values into PowerShell / .Net scripts (including for use with AD attributes c, co, countrycode), there's a NuGet/PSGallery solution that you may be interested in: https://github.com/ilyabreev/Bia.Countries

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment