We use cookies to improve your experience.
By your continued use of this site you accept such use.
For more details please see our privacy policy and cookies policy.

Script Repository

Update country code and country name

February 18, 2021 Views: 7310

The script automatically updates the Country Name (co) and Country Code (countryCode) attributes based on a 2-letter country code specified for Country (c).

By default, when you manually specify a user's country via Adaxes, all the 3 attributes used in Active Directory for a user's country, Country, Country Name and Country Code, are updated together. However, if you specify a country for users automatically, for example, using a business rule, you need to take care of updating all the 3 attributes yourself. This PowerShell script can be used to ease the task.

To run the script as a part of a business rule, scheduled task, or custom command, you need to use the Run a program or PowerShell script action.

Edit Remove
PowerShell
# TODO: Specify country info @{"two-letter country code" = @("Country name", "Country code");
#                             "two-letter country code" = @("Country name", "Country code")}
$countryInfo = @{
    "US" = @("United States", "840");
    "AL" = @("Albania", "8");
    "AR" = @("Argentina", "32");
    "AU" = @("Australia", "36");
    "AT" = @("Austria", "40");
    "BY" = @("Belarus", "112");
    "BE" = @("Belgium", "56");
    "BR" = @("Brazil", "76");
    "BG" = @("Bulgaria", "100");
    "CA" = @("Canada", "124");
    "CL" = @("Chile", "152");
    "CN" = @("China", "156");
    "CO" = @("Colombia", "170");
    "CR" = @("Costa Rica", "188");
    "HR" = @("Croatia", "191");
    "CZ" = @("Czech Republic", "203");
    "DK" = @("Denmark", "208");
    "EE" = @("Estonia", "233");
    "FI" = @("Finland", "246");
    "FR" = @("France", "250");
    "DE" = @("Germany", "276");
    "GR" = @("Greece", "300");
    "HK" = @("Hong Kong", "344");
    "HU" = @("Hungary", "348");
    "IN" = @("India", "356");
    "ID" = @("Indonesia", "360");
    "IE" = @("Ireland", "372");
    "IT" = @("Italy", "380");
    "JP" = @("Japan", "392");
    "KZ" = @("Kazakhstan", "398");
    "KP" = @("Democratic People's Republic of Korea", "408");
    "KR" = @("Republic of Korea", "410");
    "LV" = @("Latvia", "428");
    "LT" = @("Lithuania", "440");
    "MY" = @("Malaysia", "458");
    "MX" = @("Mexico", "484");
    "ME" = @("Montenegro", "499");
    "NL" = @("Netherlands", "528");
    "NZ" = @("New Zealand", "554");
    "NO" = @("Norway", "578");
    "PK" = @("Pakistan", "586");
    "PA" = @("Panama", "591");
    "PE" = @("Peru", "604");
    "PH" = @("Philippines", "608");
    "PL" = @("Poland", "616");
    "PT" = @("Portugal", "620");
    "RO" = @("Romania", "642");
    "RU" = @("Russian Federation", "643");
    "SA" = @("Saudi Arabia", "682");
    "RS" = @("Serbia", "688");
    "SG" = @("Singapore", "702");
    "SK" = @("Slovakia", "703");
    "ZA" = @("South Africa", "710");
    "ES" = @("Spain", "724");
    "SE" = @("Sweden", "752");
    "CH" = @("Switzerland", "756");
    "TW" = @("Taiwan, Province of China", "158");
    "TH" = @("Thailand", "764");
    "TR" = @("Turkey", "792");
    "UA" = @("Ukraine", "804");
    "AE" = @("United Arab Emirates", "784");
    "GB" = @("United Kingdom", "826");
    "VN" = @("VietNam", "704");
    "IL" = @("Israel", "376")} # TODO: modify me
try
{
    $country = $Context.TargetObject.Get("c")
}
catch
{
    $country = $NULL
}
if ($country -eq $NULL)
{
    # Clear country name and country code
    $Context.TargetObject.Put("co", $NULL)
    $Context.TargetObject.Put("countryCode", 0)
}
else
{
    # Update country name and country code
    $Context.TargetObject.Put("co", ($countryInfo[$country])[0])
    $Context.TargetObject.Put("countryCode", ($countryInfo[$country])[1])
}
# Save changes
$Context.TargetObject.SetInfo()
Comments 2
avatar
Anonymous Mar 22, 2019
This script doesn't have a complete list of countries.
avatar
Support Mar 22, 2019

Hello,

You can update the list of countries specified in the $countryInfo variable the way you need. Each country information should meet the following template:
"two-letter country code" = @("Country name", "Country code"

Leave a comment
Loading...

Got questions?

Support Questions & Answers