Do you have a scripting-related question or problem? You can send your question or problem to email@example.com.
I need to update the Country/region setting for hundreds of users in Active Directory (AD), which we're running on Windows 2000 Service Pack 3 (SP3) machines. When I run the test script that Listing 1 shows, I can see the changes in ADSI Edit, but the Country/region setting in each user's Address property page in the Microsoft Management Console (MMC) Active Directory Users and Computers snap-in remains unchanged. What am I missing?
You're missing the attribute that sets the Country/region setting—that is, the cn=Country-Name attribute. The lDAPDisplayName for the Country-Name attribute is a lowercase c. To fix your script, simply add the following statement before the objUser.SetInfo statement:
objUser.Put "c", "GB"
The code at callout A in Listing 2 highlights the addition you need to make. The script in Listing 2 duplicates the behavior of changing the Country/region setting through the UI of the Active Directory Users and Computers snap-in. After you run Listing 2, you should see the user's Country/region setting updated in the Active Directory Users and Computers snap-in.
If you were trying to use the Active Directory Users and Computers snap-in and ADSI Edit to figure out which attributes to set—and it sounds like you were—I'm not surprised you overlooked the Country-Name attribute. If it's any comfort, you're not the first person to ask me this question. Here's why. When you use Active Directory Users and Computers to change a user's Country/region setting, not one but three of the user's attributes are modified in AD: Country-Name, Text-Country, and Country-Code. Table 1 describes these attributes.
You use the Country-Name attribute to set a user's Country/region setting on the user's Address property page. The confusing part is that the value of the Text-Country attribute (which has the lDAPDisplayName of co) matches the text displayed in the Country/region drop-down list box. So, if you're trying to use ADSI Edit to reverse-engineer this attribute, you can easily conclude that Text-Country is the attribute you need to set to modify a user's Country/region setting. That's not the case, however.
If you're trying to write a script that duplicates the behavior of manually setting the Country/region option in Active Directory Users and Computers, you need to make sure you update all three attributes. You can use the script that Listing 3 shows to find out the current settings for these attributes. Web Table 1 (http://www.winscriptingsolutions.com, InstantDoc ID 40226) lists the values for the three attributes for more than 240 geographic areas.