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?
 
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.
0
 
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"....
0
 
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

0
 
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

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.