I’ve written a bit about vCards in the past mostly these where import scripts but one of the other ways you can use vCards with CDOEX is if you want to export active directory users or contacts to be used in another system. Basically with CDOEX you can use Iperson to create or modify Active directory users or contacts see the Exchange SDK for samples. You can also go the same way and use CDOEX and the GetvCardStream stream method to export an Active Directory user or contact to a vcard. eg
set iper = createobject("CDO.Person")
iper.datasource.open "LDAP://userdn"
Set strm = iper.GetvCardStream
strm.savetofile "c:\exp.vcf"
So if we expand out this idea a bit say I want to export the Exchange GAL to use in the palm desktop I can use an ADSI query to return all the distinguishedName’s of the user’s in the Exchange GAL and then use CDOEX and Iperson to connect to each object and use GetvCardStream method to get the Vcard text stream and create a vcard that contains all the users in the Exchange GAL that can them be imported in the palm desktop or any other application that you might want to have the Exchange GAL imported into.
I’ve created 2 versions of the script to do this the first version exptovcardsng.vbs exports all the users in the Exchange GAL to a single vcf file which is useful for programs like the Palm desktop. The other version exports all the users in the gal to separate VCF files for each user. Because these scripts use LDAP they don’t need to be run directly on a Exchange server as long as you have CDOEX installed locally on the workstation you are running the script from. I’ve put a downloadable copy of the 2 scripts here
The script itself looks like
Set objSystemInfo = CreateObject("ADSystemInfo")
set iper = createobject("CDO.Person")
strdname = objSystemInfo.DomainShortName
set conn = createobject("ADODB.Connection")
set com = createobject("ADODB.Command")
Set iAdRootDSE = GetObject("LDAP://RootDSE")
strNameingContext = iAdRootDSE.Get("defaultNamingContext")
Conn.Provider = "ADsDSOObject"
Conn.Open "ADs Provider"
Query = "<LDAP://" & strNameingContext & ">;(&(&(&(& (mailnickname=*)(!msExchHideFromAddressLists=TRUE)(|(&(objectCategory=person)
(objectClass=user)(msExchHomeServerName=*)) )))));samaccountname,displayname,distinguishedName;subtree"
Com.ActiveConnection = Conn
Com.CommandText = Query
Com.Properties("Page Size") = 1000
Set Rs = Com.Execute
vcardwrite = ""
While Not Rs.EOF
iper.datasource.open "LDAP://" & rs.fields("distinguishedName")
Set strm = iper.GetvCardStream
vcardwrite = vcardwrite & strm.readtext & vbcrlf
rs.movenext
Wend
Set fso = CreateObject("Scripting.FileSystemObject")
set wfile = fso.opentextfile("c:\temp\export.vcf",2,true)
wfile.writeline vcardwrite
wfile.close
set wfile = nothing
set iper = createobject("CDO.Person")
iper.datasource.open "LDAP://userdn"
Set strm = iper.GetvCardStream
strm.savetofile "c:\exp.vcf"
So if we expand out this idea a bit say I want to export the Exchange GAL to use in the palm desktop I can use an ADSI query to return all the distinguishedName’s of the user’s in the Exchange GAL and then use CDOEX and Iperson to connect to each object and use GetvCardStream method to get the Vcard text stream and create a vcard that contains all the users in the Exchange GAL that can them be imported in the palm desktop or any other application that you might want to have the Exchange GAL imported into.
I’ve created 2 versions of the script to do this the first version exptovcardsng.vbs exports all the users in the Exchange GAL to a single vcf file which is useful for programs like the Palm desktop. The other version exports all the users in the gal to separate VCF files for each user. Because these scripts use LDAP they don’t need to be run directly on a Exchange server as long as you have CDOEX installed locally on the workstation you are running the script from. I’ve put a downloadable copy of the 2 scripts here
The script itself looks like
Set objSystemInfo = CreateObject("ADSystemInfo")
set iper = createobject("CDO.Person")
strdname = objSystemInfo.DomainShortName
set conn = createobject("ADODB.Connection")
set com = createobject("ADODB.Command")
Set iAdRootDSE = GetObject("LDAP://RootDSE")
strNameingContext = iAdRootDSE.Get("defaultNamingContext")
Conn.Provider = "ADsDSOObject"
Conn.Open "ADs Provider"
Query = "<LDAP://" & strNameingContext & ">;(&(&(&(& (mailnickname=*)(!msExchHideFromAddressLists=TRUE)(|(&(objectCategory=person)
(objectClass=user)(msExchHomeServerName=*)) )))));samaccountname,displayname,distinguishedName;subtree"
Com.ActiveConnection = Conn
Com.CommandText = Query
Com.Properties("Page Size") = 1000
Set Rs = Com.Execute
vcardwrite = ""
While Not Rs.EOF
iper.datasource.open "LDAP://" & rs.fields("distinguishedName")
Set strm = iper.GetvCardStream
vcardwrite = vcardwrite & strm.readtext & vbcrlf
rs.movenext
Wend
Set fso = CreateObject("Scripting.FileSystemObject")
set wfile = fso.opentextfile("c:\temp\export.vcf",2,true)
wfile.writeline vcardwrite
wfile.close
set wfile = nothing