Modificar la información del usuario

Nos provee de una interfaz grafica que nos permite modificar la información del usuario.

<head>
<title>Staff details editor</title>
<HTA:APPLICATION
     APPLICATIONNAME="Staff details editor"
     SCROLL="YES"
     SINGLEINSTANCE="YES"
>
</head>

<script language="VBScript">
Const strDomainPath = "ou=Staff,dc=Contoso,dc=com"

Sub StaffSelected
  strStaffLDAP = StaffDropDown.Value
  Set objUser = GetObject(strStaffLDAP)

  ' If the employee has a manager defined, prefix the string with "LDAP://" to make it easier to compare against ADsPath strings
  If objUser.Manager<>"" Then
    strManagerLDAP = "LDAP://" & objUser.Manager
  End If

  ' Build the form HTML
  strSpanHTML = "<p>Job title: <input type=" & Chr(34) & "text" & Chr(34) & " name=" & Chr(34) & "JobTitle" & Chr(34) & " size=50><br>"
  strSpanHTML = strSpanHTML & "Manager: <select name=" & Chr(34) & "ManagerDropDown" & Chr(34) & "></select><br>"
  strSpanHTML = strSpanHTML & "Department: <input type=" & Chr(34) & "text" & Chr(34) & " name=" & Chr(34) & "Department" & Chr(34) & "></p>"
  strSpanHTML = strSpanHTML & "<p><input class=" & Chr(34) & "button" & Chr(34) & " type=" & Chr(34) & "button" & Chr(34) & " value=" & Chr(34) & "Save changes" & Chr(34) & " onClick=" & Chr(34) & "SaveButton" & Chr(34) & ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
  strSpanHTML = strSpanHTML & "<input class=" & Chr(34) & "button" & Chr(34) & " type=" & Chr(34) & "button" & Chr(34) & " value=" & Chr(34) & "Cancel" & Chr(34) & " onClick=" & Chr(34) & "CancelButton" & Chr(34) & "></p>"

  ' Plonk it onto the page
  Output.InnerHTML = strSpanHTML

  ' Build the Manager drop-down list
  ' We can do this by copying the staff list, since it is going to be the same list of names
  For Each objOption in StaffDropDown.Options
    Set objManager = Document.CreateElement("OPTION")
    objManager.Text = objOption.Text
    objManager.Value = objOption.Value
    ManagerDropDown.Add(objManager)
    If objManager.Value = strManagerLDAP Then
      objManager.Selected = True
    End If
  Next

  ' Fill in the other missing details
  JobTitle.Value = objUser.title
  Department.Value = objUser.department
End Sub

Sub SaveButton
  ' Just write all three values out
  strStaffLDAP = StaffDropDown.Value
  Set objUser = GetObject(strStaffLDAP)

  If JobTitle.value <> "" Then
    objUser.Put "title", JobTitle.Value
  End If
  If Department.value <> "" Then
    objUser.Put "department", Department.Value
  End If

  ' Manager is slightly more tricky as we have to strip the LDAP:// bit off the ADsPath
  strManager = ManagerDropDown.Value
  If strManager <> "" Then
    strManager = Mid(strManager, 8)
  End If
  objUser.Put "manager", strManager

  CancelButton
  On Error Resume Next
  objUser.SetInfo
  If Err.Number = 0 Then
    Output.InnerHTML = "<p>User information updated successfully.</p>"
  Else
    Output.InnerHTML = "<P>Error while setting user information: " & Err.Description & "</p>"
  End If
End Sub

Sub CancelButton
  Output.InnerHTML = ""

  ' Reset the staff picker to the Select... option
  bolSelected = True
  For Each objOption in StaffDropDown.Options
    objOption.Selected = bolSelected
    bolSelected = False
  Next
End Sub

Sub Window_Onload
  Const ADS_SCOPE_SUBTREE = 2

  self.ResizeTo 439,216

  Set objConnection = CreateObject("ADODB.Connection")
  Set objCommand =   CreateObject("ADODB.Command")
  objConnection.Provider = "ADsDSOObject"
  objConnection.Open "Active Directory Provider"
  Set objCommand.ActiveConnection = objConnection

  objCommand.Properties("Page Size") = 1000
  objCommand.Properties("Searchscope") = ADS_SCOPE_SUBTREE 

  objCommand.CommandText = _
    "SELECT Name, ADsPath FROM 'LDAP://" & strDomainPath & "' WHERE objectCategory='user' ORDER BY Name"
  Set objRecordSet = objCommand.Execute

  objRecordSet.MoveFirst
  Do Until objRecordSet.EOF
    Set objOption = Document.createElement("OPTION")
    objOption.Text = objRecordSet.Fields("Name").Value
    objOption.Value = objRecordSet.Fields("ADsPath").Value
    StaffDropDown.Add(objOption)
    objRecordSet.MoveNext
  Loop
End Sub
</script>

<body>
Name: <select name="StaffDropDown" onChange="StaffSelected">
<option value="">Select ...</option>
</select>
<span id="Output"></span>
</body>
Anuncios

Crear cuentas de usuario en Directorio Activo a partir de un fichero

Los campos deberán estar separados por comas.

 

'* description: create AD user accounts from the text file created by the export script.
'* author: Chris Pilling.
'* date: 18 June 2008.
'* I create an OU called import to create the accounts in then move the users around using dsa.msc.
'* REMEMBER to delete system generated accounts from the text file before running.
'* This script will quit if an account in the text file duplicates an existing one.
'* you will need to edit the FQDN for the UPN in the text file if your new AD is different from the
' one you exported from.   
 
Const ADS_UF_NORMAL_ACCOUNT = 512  
Dim strL
Const ForReading = 1
 
Set objRoot = GetObject("LDAP://RootDSE") 
varDomainNC = objRoot.Get("DefaultNamingContext") 
Set objDomain = GetObject("LDAP://" & varDomainNC) 
 
'* edit the line below to match your FQDN
 
Set objOU = GetObject("LDAP://ou=import,dc=local,dc=contoso,dc=com")
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set ts = objFSO.OpenTextFile("d:\AD_Users_Export.txt", ForReading)
Do until ts.AtEndOfStream
strL = ts.ReadLine
spl1 = Split(strL, ",")
 
wscript.echo "samAccountName = " & (spl1(0))
wscript.echo "CN = " & (spl1(0))
wscript.echo "First Name = " & (spl1(2))
wscript.echo "Last Name = " & (spl1(3))
wscript.echo "UserPrincipalName = " & (spl1(4))
wscript.echo "display name = "  & (spl1(2)) & " " & (spl1(3))
wscript.echo "Homedrive = " & (spl1(6))
wscript.echo "HomeDirectory = " & (spl1(7))
wscript.echo "LoginScript = " & (spl1(8))
 
'* edit the line below to match your FQDN
 
Set objOU = GetObject("LDAP://ou=import,dc=local,dc=contoso,dc=com")
Set objUser = objOU.Create("User", "cn =" & (spl1(1)))
objUser.Put "displayName", (spl1(2)) & " " & (spl1(3))
objUser.Put "sAMAccountName", (spl1(0))
objUser.Put "givenName", (spl1(2))
objUser.Put "UserPrincipalName", (spl1(4))
objUser.Put "sn", (spl1(3))
objUser.Put "profilePath", (spl1(5))
objUser.Put "Homedrive", (spl1(6))
objUser.Put "HomeDirectory", (spl1(7))
objUser.Put "Scriptpath", (spl1(8))
objUser.SetInfo
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateFolder("\\srv01\users" & "\" & (spl1(0)))
Set objFile2 = objFSO.CreateFolder("\\srv01\profiles" & "\" & (spl1(0)))
 
objUser.AccountDisabled = FALSE
 
'* edit the password to suit
 
objUser.SetPassword("jmc.it")
objUser.SetInfo
 
Loop

Exportar la información de usuario de Directorio Activo

A un ficherito csv separado por comas.

Visual Basic

'* description: export users from Active Directory to a comma separated text file.
'*  Use the text file to create users in a new AD with the accompanying import script.
'*              
'* author: Chris Pilling
'* date: 18 June 2008
'* edit the attributes exported to suit
'* after running it is probably best to delete lines from the text file for system generated accounts
 
Const ForAppending = 8
 
Set objRoot = GetObject("LDAP://RootDSE") 
strDNC = objRoot.Get("DefaultNamingContext") 
Set objDomain = GetObject("LDAP://" & strDNC)
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\AD_Users_Export.txt")
 
Call enummembers(objDomain) 
Sub enumMembers(objDomain) 
On Error Resume Next 
 
For Each objMember In objDomain  
 
If ObjMember.Class = "user" Then
 
'* edit the attributes you want to export here  
 
If Not (isempty(ObjMember.samAccountName)) Then 
    SamAccountName = ObjMember.samAccountName 
else 
    SamAccountName = "" 
End If
If Not (isempty(ObjMember.CN)) Then Cn = ObjMember.CN else Cn = "" End If
If Not (isempty(objMember.GivenName)) Then FirstName =objMember.GivenName else FirstName = "" End If
If Not (isempty(objMember.sn)) Then Lastname = ObjMember.sn else LastName = "" End If
If Not (isempty(objMember.UserPrincipalName)) Then 
    UserPrincipalName = objMember.UserPrincipalName 
    else 
    Name = "" 
End If
If Not (isempty(objMember.ProfilePath)) Then 
    ProfilePath = objMember.profilePath 
else 
    Profile = "" 
End If
If Not (isempty(ObjMember.homeDrive)) Then homeDrive = ObjMember.homeDrive else homeDrive = "" End If
If Not (isempty(ObjMember.homeDirectory)) Then 
    homeDirectory = ObjMember.homeDirectory 
else 
    homeDirectory = "" 
End If
If Not (isempty(ObjMember.Scriptpath)) Then 
    LoginScript = ObjMember.Scriptpath 
else 
    LoginScript = "" 
End If
 
set objFolder = nothing
set objFile = nothing
 
Set objTextFile = objFSO.OpenTextFile ("d:\AD_Users_Export.txt", ForAppending, True)
 
wscript.echo SamAccountName & "," & CN & "," & FirstName & "," & LastName & "," & UserPrincipalName & _
    "," & ProfilePath & ","  Homedrive & "," & Homedirectory & "," & LoginScript
 
strText1 = SamAccountName & "," & CN & "," & FirstName & "," & LastName & "," & UserPrincipalName & _
    "," & ProfilePath & "," & homedrive & "," & Homedirectory & "," & LoginScript

objTextFile.WriteLine(strText1) 
objTextFile.Close
 
End If 
  
If objMember.Class = "organizationalUnit" or OBjMember.Class = "container" Then 
enumMembers (objMember) 
End If 
Next 
End Sub