vbscript to write to AD department field for multipe users

Home Forums Scripting Windows Script Host vbscript to write to AD department field for multipe users

Viewing 1 post (of 1 total)
  • Author
    Posts
  • Avatar
    Goozer16
    Member
    #167725

    Hi there. I am new to vbscript and I already have been advised to change this script to Powershell, but I must make this work as I’ve inherited this not working script.

    This script looks to a group in AD, and if users are in that (security) group, then proceeds to change the department variable on users in designated sections in our organization, base on their memberships in those section’s security groups. It is not working and I need to get it working…

    {

    On Error Resume Next

    Set objGroup = GetObject _
    (“LDAP://CN=livetimecustomers,OU=service accounts,DC=domain,DC=com”)
    ‘ WScript.Echo objGroup.Name

    For Each objMember In objGroup.Members
    ‘ WScript.Echo vbCrlf & ” Name: ” & objMember.Name
    arrGroups = objMember.GetEx(“member”)
    If (Err.Number = 0) Then
    On Error GoTo 0
    strGroups = LCase(Join(arrGroups))

    ‘ Update Department attribute for COMMUNITY members

    If InStr(strGroups, “cn=community,ou=community,dc=domain,dc=com”) Then
    ‘ WScript.Echo vbCrlf & ” Name: ” & objMember.Name & ” is member of COMMUNITY”
    Set objUser = GetObject(objMember.ADsPath)
    objUser.department = “COMMUNITY”
    objUser.SetInfo
    End If

    ‘ Update Department attribute for ARTS members

    If InStr(strGroups, “cn=arts,ou=arts,ou,dc=domain,dc=com”) Then
    ‘ WScript.Echo vbCrlf & ” Name: ” & objMember.Name & ” is member of ARTS”
    Set objUser = GetObject(objMember.ADsPath)
    objUser.department = “ARTS”
    objUser.SetInfo
    End If

    }

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.