-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCopyADProperty.vbs
More file actions
38 lines (32 loc) · 1.01 KB
/
Copy pathCopyADProperty.vbs
File metadata and controls
38 lines (32 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Option Explicit
Dim oRootDSE, oDomain, oCon, oCmd, oRst, sDN
Dim oUser, sPropCopyFrom, sPropCopyTo, sProp
On Error Resume Next
sPropCopyFrom = "userPrincipalName"
sPropCopyTo = "company"
Set oRootDSE = GetObject("LDAP://RootDSE")
Set oDomain = GetObject( "LDAP://" & oRootDSE.Get("defaultNamingContext"))
Set oCon = CreateObject("ADODB.Connection")
Set oCmd = CreateObject("ADODB.Command")
oCon.Provider = "ADsDSOObject"
oCon.Open
oCmd.ActiveConnection = oCon
oCmd.CommandText = "<" & oDomain.ADsPath & ">;" _
& "(&(objectCategory=Person)(objectClass=user));distinguishedName;subTree"
oCmd.Properties("Page Size") = 100
oCmd.Properties("Timeout") = 60
oCmd.Properties("Cache Results") = False
Set oRst = oCmd.Execute()
Do While Not oRst.EOF
sDN = oRst.Fields("distinguishedName")
Set oUser = GetObject("LDAP://" & sDN)
sProp = oUser.Get(sPropCopyFrom)
sProp = Split(sProp, "@")
oUser.Put sPropCopyTo, sProp(0)
If Err.Number <> 0 Then
Err.Clear
End If
oUser.SetInfo
oRst.MoveNext
Loop
WScript.Echo "Done."