vbs active directory country code

Hi,
I am modifying user accounts with a vbs script.
I would like to query the AD Schema to get a list of all the availiable country codes and the Country names in AD.

coolrod_deAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobSampsonCommented:
Hi, Active Directory follows the ISO country codes for the Country property.
http://www.iso.org/iso/english_country_names_and_code_elements

Regards,

Rob.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
coolrod_deAuthor Commented:
Hi,
Thanks, but seeing as the Country Code and Name (in istallation Language) must be in AD, I was hoping to Build a Dictionary Object and then Look for the Name, dicCounties.exists and then Idetify the Country Code. I would prefer to write a Query and loop rather than 180 Lines of dicCountries.add "DE","Germany"....
RobSampsonCommented:
OK, in that case, I've created a reasonably workable solution for you.

From a computer with Internet access, you can get a generated CountryCodes.txt file by using this script.

.....
'Retrieve_Country_Codes_From_Web_To_Text_File.vbs
strURL = "http://www.iso.org/iso/english_country_names_and_code_elements"
strOutputFile = "CountryCodes.txt"
Set objHTTP = CreateObject("MSXML2.XMLHTTP") 
objHTTP.Open "GET", strURL, False
objHTTP.Send
 
strResults = ""
strPageText = Replace(Replace(Replace(objHTTP.responseText, VbCrLf, ""), VbLf, ""), vbTab, "")
intPos = InStr(strPageText, "<strong>A</strong><a name=""a..""></a>")
If intPos > 0 Then
	strPageText = Mid(strPageText, intPos)
	While strPageText <> ""
		strPageText = Mid(strPageText, InStr(strPageText, "</tr>") + 5)
		intPos = InStr(strPageText, "<td ")
		If intPos > 0 Then
			strPageText = Mid(strPageText, intPos + 4)
			strPageText = Mid(strPageText, InStr(strPageText, ">") + 1)
			strCountry = Trim(Left(strPageText, InStr(strPageText, "<") - 1))
			strPageText = Mid(strPageText, InStr(strPageText, "<td ") + 4)
			strPageText = Mid(strPageText, InStr(strPageText, ">") + 1)
			strCode = Trim(Left(strPageText, InStr(strPageText, "<") - 1))
			If strResults = "" Then
				If strCode <> "&nbsp;" And strCode <> "" Then strResults = strResults & strCountry & "|" & strCode
			Else
				If strCode <> "&nbsp;" And strCode <> "" Then strResults = strResults & VbCrLf & strCountry & "|" & strCode
			End If
		Else
			strPageText = ""
		End If
	Wend
End If
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
objOutputFile.Write strResults
objOutputFile.Close
Set objOutputFile = Nothing
 
MsgBox "Done."

Open in new window

RobSampsonCommented:

......

then you can use this script, to read that text file into a dictionary object, and query it.

Regards,

Rob.
'Put_Country_Codes_From_Text_File_Into_Dictionary_Object.vbs
'requires
'Retrieve_Country_Codes_From_Web_To_Text_File.vbs
 
strInputFile = "CountryCodes.txt"
Set objDict = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
While Not objInputFile.AtEndOfStream
	strLine = objInputFile.ReadLine
	strCounty = UCase(Split(strLine, "|")(0))
	strCode = UCase(Split(strLine, "|")(1))
	objDict.Add strCounty, strCode
Wend
objInputFile.Close
Set objInputFile = Nothing
 
strCountry = InputBox("Which country to do you want to get the code for?", "Country Name", "Australia")
If objDict.Exists(UCase(strCountry)) = True Then
	strCode = objDict(UCase(strCountry))
Else
	strCode = "ZZ"
End If
 
MsgBox strCode

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.