星期二, 10月 31, 2006

[Note]備份AD通訊錄

備份Active Directory上所有 user 的分機與 e-mail...
把下面的 code 存成 export.vbs以後,點擊兩下就可以執行了。

'Global variables
Dim oContainer
Dim OutPutFile
Dim FileSystem

'Initialize global variables
Set FileSystem = WScript.CreateObject("Scripting.FileSystemObject")
Set OutPutFile = FileSystem.CreateTextFile("msi.csv", True)
Set oContainer=GetObject("LDAP://DC=test,DC=com")

'Enumerate Container
EnumerateUsers oContainer

'Clean up
OutPutFile.Close
Set FileSystem = Nothing
Set oContainer = Nothing
WScript.Echo "Finished"
WScript.Quit(0)

Sub EnumerateUsers(oCont)
On Error resume next
Dim oUser
For Each oUser In oCont
Select Case LCase(oUser.Class)
Case "user"
'If Not IsEmpty(oUser.distinguishedName) Then
' OutPutFile.WriteLine "dn: " & oUser.distinguishedName
'End If
If Not IsEmpty(oUser.name) Then
OutPutFile.Write oUser.Get("name")
End If
OutPutFile.Write ","

If Not IsEmpty(oUser.FullName) Then
OutPutFile.Write oUser.FullName
End If
OutPutFile.Write ","

' EmailAddress
If Not IsEmpty(oUser.EmailAddress) Then
OutPutFile.Write oUser.EmailAddress
End If
OutPutFile.Write ","

If Not IsEmpty(oUser.TelephoneNumber) Then
OutputFile.Write oUser.Get("TelephoneNumber")
End If
OutPutFile.WriteLine
Case "organizationalunit" , "container"
EnumerateUsers oUser
End Select
Next
End Sub


參考資料:

沒有留言:

您或許對這些文章有興趣

Related Posts Plugin for WordPress, Blogger...