vbs active directory country code

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.

Who is Participating?

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

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.

Hi, Active Directory follows the ISO country codes for the Country property.



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:
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"....
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.

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
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
				If strCode <> "&nbsp;" And strCode <> "" Then strResults = strResults & VbCrLf & strCountry & "|" & strCode
			End If
			strPageText = ""
		End If
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
objOutputFile.Write strResults
Set objOutputFile = Nothing
MsgBox "Done."

Open in new window



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


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
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))
	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

From novice to tech pro — start learning today.