Script repository
The script updates the Country Name and Country Code attributes based on the 2-letter country code specified in the Country property. The script can be executed in business rules, scheduled tasks and custom commands configured for thre User object type.
In the script, the $countryInfo variable maps 2-letter country codes to the corresponding country names and country codes.
$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
# Example: @{"two-letter country code" = @("Country name", "Country code");
# "two-letter country code" = @("Country name", "Country code")}
try
{
$country = $Context.TargetObject.Get("c")
}
catch
{
$country = $NULL
}
if ($NULL -eq $country)
{
# 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
You must be signed in to comment.
Anonymous
This script doesn't have a complete list of countries.
Support
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: