• Products
    • View all products
    • Free trials
  • Solutions
    • All Solutions
    • All Integrations
  • Resources
    • All Resources
    • Learning Hub
  • Trials
  • Support
    • Support Home
    • By Product
      • All Products
      • Active Roles
      • Authentication Services
      • Cloud Access Manager
      • Defender
      • Identity Manager
      • Password Manager
      • Safeguard
      • Starling Identity Analytics & Risk Intelligence
      • Starling Two-Factor Authentication
      • TPAM Appliance
    • Contact Support
      • Overview
      • Customer Service
      • Licensing Assistance
      • Renewal Assistance
      • Technical Support
    • Download Software
    • Knowledge Base
    • My Account
      • My Products
      • My Service Requests
      • My Licenses
      • My Groups
      • My Profile
    • Policies & Procedures
    • Professional Services
    • Technical Documentation
    • One Identity University
    • User Forums
    • Video Tutorials
  • Partners
    • Overview
    • Partner Circle Log In
    • Become a Partner
    • Find a Partner
    • Partner Community
  • Communities
    • Home
    • Blogs
      • Blogs A to Z
      • One Identity Community
      • AD Account Lifecycle Management
      • Cloud
      • Identity Governance & Administration
      • Privileged Access Management
      • syslog-ng Community
    • Forums
      • All Product Forums
      • Active Roles
      • Identity Manager
      • Password Manager
      • Safeguard
      • Unix Access Management
    • Social Networks
      • Facebook
      • LinkedIn
      • Twitter
      • YouTube
One Identity Community
One Identity Community
  • Site
  • User
  • Site
  • Search
  • User
Active Roles Community
Active Roles Community
Wiki Manage country codes, names and abbreviations
  • Forum
  • Ideas
  • Wiki
  • More
  • Cancel
  • New
  • -Active Roles Script Center
    • +Active Roles Script Policy Best Practices
    • Active Roles SDK
    • +C#
    • +JavaScript
    • +PowerShell
    • -VBScript
      • VBScript Library source code
      • -VBScript samples
        • A Managed Unit with users which have not logged on for last 90 days
        • Adjust the case of usernames to title case (first letter of each part of the name)
        • Advanced group creation/provision
        • Advanced shared folder creation
        • Bulk policy incompliance fixing
        • Check unique value of an attribute
        • +Computer management
        • +Exchange management
        • Function that converts regular date into integer8 format
        • Get effective policy info list
        • +Group management
        • How to find a request source in script policy
        • How to send emails based on scripts policy parameters and Virtual Attribute values
        • +Permissions Management
        • Policy incompliance reporting & fixing for specified policy
        • Populate values from a SQL database to an AD Attribute
        • Prevent copying an attribute on user copy
        • Prohibite a permission propagation to AD
        • Prohibite an AD native security editing
        • Read large integer date attributes and display them in date and time readable format
        • Read XML Node text or attribute value
        • Read XML Node with Children into DictionaryObject
        • Standalone script that requests built-in password generation policy
        • -User management
          • Copy additional attributes on user copy
          • Create/Delete local user accounts, basing upon creation/deletion of user accounts in Active Directory
          • Custom script-based PVG-policy with generation rule
          • Custom script-based PVG-policy with possible values list
          • Custom script-based User Logon Name Generation policy
          • Delete Expired Users and Home Directory
          • Detailed debug information on the script policy request object
          • Function to get a DN of a user object using samAccountName
          • Get user account properties after it had been deleted
          • How to enable cross-domain moving of user accounts
          • How to enforce the use of the "Generate Password" function
          • How to prevent Active Roles interaction with file servers on User Home Folder Provision
          • How to prohibit specifying a user password that never expires
          • Last Bad Password Time
          • Manage country codes, names and abbreviations
          • Move a user to some OU upon creation
          • Notify manager when user object is deprovisioned
          • Populate a PVG policy with a possible values list from external source
          • Populate user attributes based on another attribute - e.g. 'Company'
          • Programmatically deprovision a user
          • Re-locates users according to a value set in a virtual attribute
          • Remove characters with an umlaute (öäü) and replace with corresponding characters
          • Restrict who can Disable users while allowing Enable
          • Review for user personal data
          • Script Policy to set account expiration for every created user account
          • Script-based "Last N characters of X attribute"-rule as part of User Logon Name Generation policy rules
          • Set correct country code for user
          • Simplified version of the script-based PVG-policy with a possible values list
          • Stamping manager DN by given manager Id
          • Standalone script to set logon hours of a user account
          • Tree of trust - allow objects to be managed only by their direct or indirect managers
          • User logon name generation without national characters
          • User Provisioning - Home Drive Location and Profile based on UserID
        • Validate moving operations
        • +VBScript: Approval

Manage country codes, names and abbreviations

DESCRIPTION

There are 3 attributes in Active Directory that refer to the country in a user account address. They are:

  • "co", localized country name
  • "countrycode", 3-digit country code
  • "c", 2 char country abbreviation

These names and codes described in ISO 3166 standard.

The below script is NOT completely comprehensive. For a complete listing of all country codes, please see this resource.

Active Roles Console & Active Roles Web Interface manage these 3 attributes in compliance with each other, but other Active Roles tools do not.

This script policy sample stamps appropriate country code and name by given country abbreviation.


Note This code may use functions from the Active Roles Script Policy Best Practices. Please, follow the link to obtain instructions and code for those functions.


SCRIPT

 

'*********************************************************************************

' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,

' EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED

' WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.

'

' IF YOU WANT THIS FUNCTIONALITY TO BE CONDITIONALLY SUPPORTED,

' PLEASE CONTACT ONE IDENTITY PROFESSIONAL SERVICES.

'*********************************************************************************

Option Explicit

'**********************************************************************

' Country list

'**********************************************************************

Dim arrCountries, arrCountry

arrCountries = Array( _

Array("Afghanistan", 4, "AF"), _

Array("Albania", 8, "AL"), _

Array("Algeria", 12, "DZ"), _

Array("American Samoa", 16, "AS"), _

Array("Andorra", 20, "AD"), _

Array("Angola", 24, "AO"), _

Array("Anguilla", 660, "AI"), _

Array("Antarctica", 10, "AQ"), _

Array("Antigua and Barbuda", 28, "AG"), _

Array("Argentina", 32, "AR"), _

Array("Armenia", 51, "AM"), _

Array("Aruba", 533, "AW"), _

Array("Australia", 36, "AU"), _

Array("Austria", 40, "AT"), _

Array("Azerbaijan", 31, "AZ"), _

Array("Bahrain", 48, "BH"), _

Array("Baker Island", 581, "XX"), _

Array("Bangladesh", 50, "BD"), _

Array("Barbados", 52, "BB"), _

Array("Belarus", 112, "BY"), _

Array("Belgium", 56, "BE"), _

Array("Belize", 84, "BZ"), _

Array("Benin", 204, "BJ"), _

Array("Bermuda", 60, "BM"), _

Array("Bhutan", 64, "BT"), _

Array("Bolivia", 68, "BO"), _

Array("Bosnia and Herzegovina", 70, "BA"), _

Array("Botswana", 72, "BW"), _

Array("Bouvet Island", 74, "BV"), _

Array("Brazil", 76, "BR"), _

Array("British Indian Ocean Territory", 86, "IO"), _

Array("Brunei", 96, "BN"), _

Array("Bulgaria", 100, "BG"), _

Array("Burkina Faso", 854, "BF"), _

Array("Burundi", 108, "BI"), _

Array("Cambodia", 116, "KH"), _

Array("Cameroon", 120, "CM"), _

Array("Canada", 124, "CA"), _

Array("Cape Verde", 132, "CV"), _

Array("Cayman Islands", 136, "KY"), _

Array("Central African Republic", 140, "CF"), _

Array("Chad", 148, "TD"), _

Array("Chile", 152, "CL"), _

Array("China", 156, "CN"), _

Array("Christmas Island", 162, "CX"), _

Array("Colombia", 170, "CO"), _

Array("Comoros", 174, "KM"), _

Array("Congo", 178, "CG"), _

Array("Cook Islands", 184, "CK"), _

Array("Costa Rica", 188, "CR"), _

Array("Croatia", 191, "HR"), _

Array("Cuba", 192, "CU"), _

Array("Cyprus", 196, "CY"), _

Array("Czech Republic", 203, "CZ"), _

Array("Denmark", 208, "DK"), _

Array("Djibouti", 262, "DJ"), _

Array("Dominica", 212, "DM"), _

Array("Dominican Republic", 214, "DO"), _

Array("Ecuador", 218, "EC"), _

Array("Egypt", 818, "EG"), _

Array("El Salvador", 222, "SV"), _

Array("Equatorial Guinea", 226, "GQ"), _

Array("Eritrea", 232, "ER"), _

Array("Estonia", 233, "EE"), _

Array("Ethiopia", 231, "ET"), _

Array("Faroe Islands", 234, "FO"), _

Array("Fiji Islands", 242, "FJ"), _

Array("Finland", 246, "FI"), _

Array("France", 250, "FR"), _

Array("French Guiana", 254, "GF"), _

Array("French Polynesia", 258, "PF"), _

Array("French Southern and Antarctic Lands", 260, "TF"), _

Array("Gabon", 266, "GA"), _

Array("Georgia", 268, "GE"), _

Array("Germany", 276, "DE"), _

Array("Ghana", 288, "GH"), _

Array("Gibraltar", 292, "GI"), _

Array("Greece", 300, "GR"), _

Array("Greenland", 304, "GL"), _

Array("Grenada", 308, "GD"), _

Array("Guadeloupe", 312, "GP"), _

Array("Guam", 316, "GU"), _

Array("Guatemala", 320, "GT"), _

Array("Guernsey", 826, "GG"), _

Array("Guinea", 324, "GN"), _

Array("Guyana", 328, "GY"), _

Array("Haiti", 332, "HT"), _

Array("Heard Island and McDonald Islands", 334, "HM"), _

Array("Honduras", 340, "HN"), _

Array("Howland Island", 581, "XX"), _

Array("Hungary", 348, "HU"), _

Array("Iceland", 352, "IS"), _

Array("India", 356, "IN"), _

Array("Indonesia", 360, "ID"), _

Array("Iran", 364, "IR"), _

Array("Iraq", 368, "IQ"), _

Array("Ireland", 372, "IE"), _

Array("Israel", 376, "IL"), _

Array("Italy", 380, "IT"), _

Array("Jamaica", 388, "JM"), _

Array("Jan Mayen", 744, "SJ"), _

Array("Japan", 392, "JP"), _

Array("Jarvis Island", 581, "XX"), _

Array("Jersey", 826, "JE"), _

Array("Johnston Atoll", 581, "XX"), _

Array("Jordan", 400, "JO"), _

Array("Kazakhstan", 398, "KZ"), _

Array("Kenya", 404, "KE"), _

Array("Kingman Reef", 581, "XX"), _

Array("Kiribati", 296, "KI"), _

Array("Korea", 410, "KR"), _

Array("Kuwait", 414, "KW"), _

Array("Kyrgyzstan", 417, "KG"), _

Array("Laos", 418, "LA"), _

Array("Latvia", 428, "LV"), _

Array("Lebanon", 422, "LB"), _

Array("Lesotho", 426, "LS"), _

Array("Liberia", 430, "LR"), _

Array("Libya", 434, "LY"), _

Array("Liechtenstein", 438, "LI"), _

Array("Lithuania", 440, "LT"), _

Array("Luxembourg", 442, "LU"), _

Array("Madagascar", 450, "MG"), _

Array("Malawi", 454, "MW"), _

Array("Malaysia", 458, "MY"), _

Array("Maldives", 462, "MV"), _

Array("Mali", 466, "ML"), _

Array("Malta", 470, "MT"), _

Array("Marshall Islands", 584, "MH"), _

Array("Martinique", 474, "MQ"), _

Array("Mauritania", 478, "MR"), _

Array("Mauritius", 480, "MU"), _

Array("Mayotte", 175, "YT"), _

Array("Mexico", 484, "MX"), _

Array("Micronesia", 583, "FM"), _

Array("Midway Islands", 581, "XX"), _

Array("Moldova", 498, "MD"), _

Array("Monaco", 492, "MC"), _

Array("Mongolia", 496, "MN"), _

Array("Montenegro", 499, "ME"), _

Array("Montserrat", 500, "MS"), _

Array("Morocco", 504, "MA"), _

Array("Mozambique", 508, "MZ"), _

Array("Myanmar", 104, "MM"), _

Array("Namibia", 516, "NA"), _

Array("Nauru", 520, "NR"), _

Array("Nepal", 524, "NP"), _

Array("Netherlands", 528, "NL"), _

Array("Netherlands Antilles", 530, "AN"), _

Array("New Caledonia", 540, "NC"), _

Array("New Zealand", 554, "NZ"), _

Array("Nicaragua", 558, "NI"), _

Array("Niger", 562, "NE"), _

Array("Nigeria", 566, "NG"), _

Array("Niue", 570, "NU"), _

Array("Norfolk Island", 574, "NF"), _

Array("North Korea", 408, "KP"), _

Array("Northern Mariana Islands", 580, "MP"), _

Array("Norway", 578, "NO"), _

Array("Oman", 512, "OM"), _

Array("Pakistan", 586, "PK"), _

Array("Palau", 585, "PW"), _

Array("Palestinian Authority", 275, "PS"), _

Array("Palmyra Atoll", 581, "XX"), _

Array("Panama", 591, "PA"), _

Array("Papua New Guinea", 598, "PG"), _

Array("Paraguay", 600, "PY"), _

Array("Peru", 604, "PE"), _

Array("Philippines", 608, "PH"), _

Array("Pitcairn Islands", 612, "PN"), _

Array("Poland", 616, "PL"), _

Array("Portugal", 620, "PT"), _

Array("Puerto Rico", 630, "PR"), _

Array("Qatar", 634, "QA"), _

Array("Reunion", 638, "RE"), _

Array("Romania", 642, "RO"), _

Array("Russia", 643, "RU"), _

Array("Rwanda", 646, "RW"), _

Array("Samoa", 882, "WS"), _

Array("San Marino", 674, "SM"), _

Array("Saudi Arabia", 682, "SA"), _

Array("Senegal", 686, "SN"), _

Array("Serbia", 891, "CS"), _

Array("Seychelles", 690, "SC"), _

Array("Sierra Leone", 694, "SL"), _

Array("Singapore", 702, "SG"), _

Array("Slovakia", 703, "SK"), _

Array("Slovenia", 705, "SI"), _

Array("Solomon Islands", 90, "SB"), _

Array("Somalia", 706, "SO"), _

Array("South Africa", 710, "ZA"), _

Array("South Georgia and the South Sandwich Islands", 239, "GS"), _

Array("Spain", 724, "ES"), _

Array("Sri Lanka", 144, "LK"), _

Array("Sudan", 736, "SD"), _

Array("Suriname", 740, "SR"), _

Array("Svalbard", 744, "SJ"), _

Array("Swaziland", 748, "SZ"), _

Array("Sweden", 752, "SE"), _

Array("Switzerland", 756, "CH"), _

Array("Syria", 760, "SY"), _

Array("São Tomé and Príncipe", 678, "ST"), _

Array("Taiwan", 158, "TW"), _

Array("Tajikistan", 762, "TJ"), _

Array("Tanzania", 834, "TZ"), _

Array("Thailand", 764, "TH"), _

Array("Togo", 768, "TG"), _

Array("Tokelau", 772, "TK"), _

Array("Tonga", 776, "TO"), _

Array("Trinidad and Tobago", 780, "TT"), _

Array("Tunisia", 788, "TN"), _

Array("Turkey", 792, "TR"), _

Array("Turkmenistan", 795, "TM"), _

Array("Turks and Caicos Islands", 796, "TC"), _

Array("Tuvalu", 798, "TV"), _

Array("Uganda", 800, "UG"), _

Array("Ukraine", 804, "UA"), _

Array("United Arab Emirates", 784, "AE"), _

Array("United Kingdom", 826, "GB"), _

Array("United States", 840, "US"), _

Array("Uruguay", 858, "UY"), _

Array("Uzbekistan", 860, "UZ"), _

Array("Vanuatu", 548, "VU"), _

Array("Vatican City", 336, "VA"), _

Array("Venezuela", 862, "VE"), _

Array("Vietnam", 704, "VN"), _

Array("Virgin Islands", 850, "VI"), _

Array("Wake Island", 581, "XX"), _

Array("Wallis and Futuna", 876, "WF"), _

Array("Western Sahara", 732, "EH"), _

Array("Yemen", 887, "YE"), _

Array("Zambia", 894, "ZM"), _

Array("Zimbabwe", 716, "ZW"), _

Array("Åland Islands", 248, "AX"))

'**********************************************************************

' EVENT HANDLERS

'**********************************************************************

Sub onPreModify(Request)

'--- trigger only if user object is modified -------

If (Not IsObjectClassRequested("user", Request) The Exit Sub

'--- trigger only if country code is modified -------

If (Not IsAtttributeModified("c", Request) The Exit Sub

Dim strAbbreviation, arrCountry

'--- Get country code from request -------

strAbbreviation = GetAttribute("c", Request)

'--- if there is not a code -------

If (IsEmpty(strAbbreviation)) Then

'--- clear country name and abbreviation -------

Request.PutEx ADS_PROPERTY_CLEAR, "co", Empty

Request.PutEx ADS_PROPERTY_CLEAR, "countryCode", Empty

Else

'--- get country info from country list ---

arrCountry = FindCountryByAbbreviation(strAbbreviation)

'--- exit if that country was not found in country list ---

If (IsEmpty(arrCountry)) Then Exit Sub

'--- set apporiate country name and code -------

Request.Put "co", arrCountry(0)

Request.Put "countryCode", arrCountry(1)

End If

End Sub

'**********************************************************************

' Helping routines

'**********************************************************************

Function FindCountryByName(ByVal strName)

Dim arrCountry

For Each arrCountry in arrCountries

If (LCase(arrCountry(0)) = LCase(strName)) Then

FindCountryByName = arrCountry

Exit Function

End If

Next

FindCountryByName = Empty

End Function

Function FindCountryByCode(ByVal numCode)

Dim arrCountry

For Each arrCountry in arrCountries

If (arrCountry(1) = numCode) Then

FindCountryByCode = arrCountry

Exit Function

End If

Next

FindCountryByCode = Empty

End Function

Function FindCountryByAbbreviation(ByVal strAbbreviation)

Dim arrCountry

For Each arrCountry in arrCountries

If (LCase(arrCountry(2)) = LCase(strAbbreviation)) Then

FindCountryByAbbreviation = arrCountry

Exit Function

End If

Next

FindCountryByAbbreviation = Empty

End Function

'***** END OF CODE ***************************************************************

  • Script Center
  • Script Center: VBScript
  • Share
  • History
  • More
  • Cancel
Related
Recommended
  • Company
    • About Us
    • Buy
    • Careers
    • Contact Us
    • News
  • Resources
    • Blogs
    • Customer Stories
    • Documents
    • Events
    • Videos
  • Support
    • Professional Services
    • Renew Support
    • Technical Support
    • One Identity University
    • Support Service
  • Social Networks
    • Facebook
    • Instagram
    • LinkedIn
    • Twitter
    • YouTube
  • © 2025 One Identity LLC. ALL RIGHTS RESERVED.
  • Legal
  • Terms of Use
  • Privacy
  • Community Feedback & Support
  • Cookie Preference Center