trafil sie ostatnio taki problem - wdrozylismy AD+EX i klient poprosil o pomoc przy przeniesieniu kontatkow z outlook do AD. generalnie nic trudnego - mozna zalatwic to prostym skryptem, jest jednak pewien myk. oto kilka uwag dotyczacych takiej operacji:
najpierw sam skrypt. przy pelnym exportcie kontatow z outlooka dostaje sie plik excelowy z gigantyczna iloscia kolumn. najpier wiec definicja pol:
const X_SALUTATION=1
const X_GN=2
const X_SN=4
CONST X_COMPANY=6
CONST X_DEPT=7
CONST X_TITLE=8
CONST X_ADDR=9
CONST X_CITY=12
CONST X_STATE=13
CONST X_ZIP=14
CONST X_COUNTRY=15
CONST X_ASSISTANT=30
const X_FAX=31
CONST X_TEL=32
CONST X_TEL2=33
CONST X_MOBILE=41
CONST X_TEL3=43
CONST X_PAGER=44
CONST X_EMAIL=49
CONST X_ENAME=51
CONST X_NOTES=73
CONST X_WEBPAGE=85
skrypt jest dosc prymitywny - na szybko - zalozeniem jest wiec, ze jedno z pol - tu 'nazwisko' - jest zawsze niepuste. skrypt bedzie przetwarzal arqsz excela az trafi na wiersz z pusta kolumna 'nazwisko'. przed przypisaniem kazdej wartosci do AD trzeba sprawdzic czy nie jest ona przypadkiem pusta:
Set objRoot = GetObject("LDAP://rootDSE")
strDNS = objRoot.Get("defaultNamingContext") 
Set objDomain = GetObject("LDAP://" & strDNS)
Set objOU = GetObject("LDAP://OU=contacts," & strDNS)
set oExcel=createobject("Excel.Application")
oExcel.workbooks.open(left( WScript.ScriptFullname, instrRev(WScript.ScriptFullname,"\") )&"kontakty-import.xls")
i=2
with oExcel.ActiveSheet    
While .Cells(i,X_SN) <> ""
  wscript.echo vbcrlf&"przetwazam wiersz: "&cstr(i)
tu jeszcze informacja - podczas importu kontaktow, trzeba pamietac o tym, ze aby pojawily sie one w ksiazce adresowej, musza byc uzupelnione wszystkie pola wymagane przez exchange - inaczej utworzonego contactu nie bedzie w GALach. czesc z atrybutow uzupelnia sie sama, ale czesc trzeba przypisac recznie - to jest glownie cn oraz mailnickname:
  surname=.cells(i,X_SN).Value
  givenname=.cells(i,X_GN).value
  if not isNull(givenname) and not isEmpty(givenname) then
    contactname=givenname&" "&surname
  else
    contactname=surname
  end if
  wscript.echo contactname   
  Set objContact = objOU.Create("contact", "cn="&contactname)
 
  wscript.echo "nazwisko: "&.cells(i,X_SN).Value  
  objContact.put "sn",.cells(i,X_SN).Value
  objContact.put "mailNickName", contactname
  if not isNull(.cells(i,X_GN).Value) and not isEmpty(.cells(i,X_GN).Value) then
    wscript.echo "imie: "&.cells(i,X_GN).Value  
    objContact.put "givenName",.cells(i,X_GN).Value
  end if  
  if not isNull(.cells(i,X_SALUTATION).Value) and not isEmpty(.cells(i,X_SALUTATION).Value) then
    wscript.echo "salut/desc: "&.cells(i,X_SALUTATION).Value  
    objContact.put "description",.cells(i,X_SALUTATION).Value
  end if  
  if not isNull(.cells(i,X_COMPANY).Value) and not isEmpty(.cells(i,X_COMPANY).Value) then
    wscript.echo "company: "&.cells(i,X_COMPANY).Value 
    objContact.put "company", .cells(i,X_COMPANY).Value
  end if  
  if not isNull(.cells(i,X_DEPT).Value) and not isEmpty(.cells(i,X_DEPT).Value) then
    wscript.echo "department: "&.cells(i,X_DEPT).Value 
    objContact.put "department", .cells(i,X_DEPT).Value  
  end if  
  if not isNull(.cells(i,X_TITLE).Value) and not isEmpty(.cells(i,X_TITLE).Value) then
    wscript.echo "title: "&.cells(i,X_TITLE).Value
    objContact.put "title", .cells(i,X_TITLE).Value  
  end if  
  if not isNull(.cells(i,X_ADDR).Value ) and not isEmpty(.cells(i,X_ADDR).Value ) then
    wscript.echo "street: "&.cells(i,X_ADDR).Value  
    objContact.put "street",.cells(i,X_ADDR).Value
  end if  
  if not isNull(.cells(i,X_CITY).Value ) and not isEmpty(.cells(i,X_CITY).Value ) then
    wscript.echo "city: "&.cells(i,X_CITY).Value  
    objContact.put "l",.cells(i,X_CITY).Value
  end if  
  if not isNull(.cells(i,X_STATE).Value ) and not isEmpty(.cells(i,X_STATE).Value ) then
    wscript.echo "state: "&.cells(i,X_STATE).Value  
    objContact.put "st",.cells(i,X_STATE).Value
  end if  
  if not isNull(.cells(i,X_ZIP).Value) and not isEmpty(.cells(i,X_ZIP).Value) then
    wscript.echo "postal: "&.cells(i,X_ZIP).Value  
    objContact.put "postalCode",.cells(i,X_ZIP).Value
  end if  
  'if not isNull(.cells(i,X_COUNTRY).Value) and not isEmpty(.cells(i,X_COUNTRY).Value) then
  '  wscript.echo .cells(i,X_COUNTRY).Value  
  '  objContact.put "",
  'end if  
  if not isNull(.cells(i,X_ASSISTANT).Value ) and not isEmpty(.cells(i,X_ASSISTANT).Value ) then
    wscript.echo "asist/info: "&.cells(i,X_ASSISTANT).Value  
    info="telefon do asystenta: "&.cells(i,X_ASSISTANT).Value
  end if  
  if not isNull(.cells(i,X_FAX).Value) and not isEmpty(.cells(i,X_FAX).Value) then
    wscript.echo "fax: "&.cells(i,X_FAX).Value  
    objContact.put "facsimileTelephoneNumber",.cells(i,X_FAX).Value
  end if  
  if not isNull(.cells(i,X_TEL).Value ) and not isEmpty(.cells(i,X_TEL).Value ) then
    wscript.echo "telefon: "&.cells(i,X_TEL).Value  
    objContact.put "telephoneNumber",.cells(i,X_TEL).Value
  end if  
  if not isNull(.cells(i,X_TEL2).Value) and not isEmpty(.cells(i,X_TEL2).Value) then
    wscript.echo "othertel1: "&.cells(i,X_TEL2).Value  
    othel=.cells(i,X_TEL2).Value
  end if  
  if not isNull(.cells(i,X_MOBILE).Value) and not isEmpty(.cells(i,X_MOBILE).Value) then
    wscript.echo "mobile: "&.cells(i,X_MOBILE).Value  
    objContact.put "mobile",.cells(i,X_MOBILE).Value
  end if  
  if not isNull(.cells(i,X_TEL3).Value) and not isEmpty(.cells(i,X_TEL3).Value) then
    wscript.echo "othertel2: "&.cells(i,X_TEL3).Value
    if isNull(othel) or isEmpty(othel) then  
      othel=.cells(i,X_TEL3).Value
    else
      othel=othel&","&.cells(i,X_TEL3).Value
    end if
  end if  
  if not isNull(.cells(i,X_PAGER).Value) and not isEmpty(.cells(i,X_PAGER).Value) then
    wscript.echo "pager: "&.cells(i,X_PAGER).Value  
    objContact.put "pager",.cells(i,X_PAGER).Value
  end if  
  if not isNull(.cells(i,X_EMAIL).Value) and not isEmpty(.cells(i,X_EMAIL).Value) and instr(.cells(i,X_EMAIL).Value,"@")>1 then
    wscript.echo "email: "&.cells(i,X_EMAIL).Value  
    objContact.put "mail",.cells(i,X_EMAIL).Value
  end if  
  if not isNull(.cells(i,X_ENAME).Value) and not isEmpty(.cells(i,X_ENAME).Value) then
    wscript.echo "enote: "&.cells(i,X_ENAME).Value  
    'objContact.put "",
  end if  
  if not isNull(.cells(i,X_NOTES).Value ) and not isEmpty(.cells(i,X_NOTES).Value ) then
    wscript.echo "notes: "&.cells(i,X_NOTES).Value  
    info=info & vbCrLf & .cells(i,X_NOTES).Value
  end if  
  if not isNull(.cells(i,X_WEBPAGE).Value) and not isEmpty(.cells(i,X_WEBPAGE).Value) then
    wscript.echo "www: "&.cells(i,X_WEBPAGE).Value  
    objContact.put "wwwHomePage",.cells(i,X_WEBPAGE).Value
  end if  
  
  if not isNull(info) and not isEmpty(info) then
    objContact.put "info", info
  end if
  if not isNull(othel) and not isEmpty(othel) then
    objContact.putex 2,"otherTelephone",split(othel,",")
  end if
 on error resume next
  objContact.setInfo
  if err.number<>0 then 
    wscript.echo "blad zakladania usera: "&contactname&" "&err.description
    err.clear
  else
    wscript.echo "DONE."
  end if
  i=i+1
wend
end with
oExcel.Quit
czesc dotyczaca kraju zostala wyremowana, poniewaz kraj opisuje sie w AD countrycode wg numerkow ISO 3166 wiec trzba by stworzyc tabele realicji. nie przy tak prywmitywnym skrypciq.
to nie jest jednak koniec problemow - podczas importu kontaktow, RUS [recipient update service], automatycznie zaktualizajuje wszystkie kontakty. w rezultacie swierzo zaimportowane kontakty beda mialy maile.. firmowe. aby RUS nie podmienil kontkaktow mozna skorzystac z tego opisu lub z narzedzia admodify w zakladce 'email addr' zaznaczajac jeden z dwoch checkboxow przy 'update recipient policy ....'. mozna tez, korzystajac z artykulu z ms dodac do skryptu update dodatkowego pola w AD:
objContact.put "msExchPoliciesExcluded","{3B6813EC-CE89-42BA-9442-D87D4AA30DBC}"
tego jednak nie testowalem, a w innym artykule podana jest nieco inna wartosc: "{26491CFC-9E50-4857-861B-0CB8DF22B5D7}" - taka tez wartosc znalazlem w AD po skorzystaniu z ADModify. 
jesli zdarzy sie koniecznosc ponownego importu, na pewno to przetestuje q:
poniedziałek, stycznia 08, 2007
export kontaktow outlook express do AD
Posted by
n€x¤R
at
14:03
 
 
Labels: article, exchange, script, tips'n'tricks
Subskrybuj:
Komentarze do posta (Atom)
 
Brak komentarzy:
Prześlij komentarz