Novell Home

Doing a Mass Modify after User Add Operations

Novell Cool Solutions: Feature
By Rob Schneider

Digg This - Slashdot This

Posted: 3 Jan 2007
 

Problem

Imagine: You've just migrated 15,000 users from a production tree into a lab tree. You tried to migrate the entire user object, but received errors during the LDIF, so you migrated a subset of user attributes. You are very happy the work's done.

But then you discover that you are missing three critical attributes from every user. You can't do the ICE "Migrate Data Between LDAP Servers" or an LDIF - those are Add operations, and you need a Modify. What to do?

Solution

1. Extract a new LDIF file of all users in the source tree, containing the attributes you need to modify on every user.

2. Run the Microsoft Word Macro attached below.

3. Import the beautiful, clean LDIF file that results.

This works on any number of attributes.

The macro reformats the LDIF file, converting the Add operation to Modify operations, and reformatting each attribute modification to "replace" the non-existent value in the destination tree.

Copy the following VB Macro into your MSWord Normal Template, and you're off to the races.

Hopefully this will save you as much time as it has saved me, on multiple occasions.

Example

Sub MultiAttrModifyLDIF()

'
' MultiAttrModifyLDIF Macro
' Macro recorded 08/03/2006 by Rob Schneider
'
' Mark all Double Returns with a distinct pattern
' Useful later.
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "^p^p"
        .Replacement.Text = "^p^p###"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
        Selection.Find.ClearFormatting
    
' Convert changetype to Modify
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "changetype: add"
        .Replacement.Text = "changetype: modify"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

' Identify the beginning of the next record.  If none, then exit
RecordPosition:
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "changetype: modify"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
                If Selection.Find.Found = False Then GoTo ennd
    Selection.MoveRight Unit:=wdCharacter, Count:=2
      
    GoTo AttribFormat
    GoTo RecordPosition
ennd:
    End

' Search for the next Record delimiter ### and extend the selection
AttribFormat:
    Selection.Extend
    Selection.Find.ClearFormatting
    With Selection.Find
        .Text = "###"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
    Selection.EscapeKey
    Selection.Find.ClearFormatting
'Search within that selection for a colon.  If there are colons, it is an attribute.
    With Selection.Find
        .Text = ":"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindStop
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute
' If no colon is found, then clear selection and begin again at RecordPosition
            If Selection.Find.Found = False Then
            Selection.TypeBackspace
            Selection.MoveUp Unit:=wdLine, Count:=1
            Selection.Delete Unit:=wdCharacter, Count:=1
            GoTo RecordPosition
            End If
' If a colon is found in the selection, do gyrations to format attribute for a Replace operation
    
    Selection.MoveLeft Unit:=wdCharacter, Count:=1
    Selection.Extend
    Selection.HomeKey Unit:=wdLine
    Selection.Copy
    Selection.HomeKey Unit:=wdLine
    Selection.TypeParagraph
    Selection.MoveUp Unit:=wdLine, Count:=1
    Selection.TypeText Text:="replace: "
    Selection.Paste
    Selection.HomeKey Unit:=wdLine
    Selection.MoveDown Unit:=wdLine, Count:=2
    Selection.TypeText Text:="-"
    Selection.TypeParagraph
    GoTo AttribFormat
End Sub


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell