Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem deleting proxyAddresses values with PutEx ? 2

Status
Not open for further replies.

shinedog

MIS
Feb 24, 2004
60
0
0
US
Hey all, I got what I think should be a relatively simple script.

Code:
Const ADS_PROPERTY_CLEAR = 1 
Const ADS_PROPERTY_DELETE = 4

strDN = InputBox("Enter the distinguishedName:","Clean up rfax: addresses")

Set objUser = GetObject("LDAP://" & strDN)

For Each strAddress In objUser.proxyAddresses
	If Left(strAddress,5) = "rfax:" Then
		objUser.PutEX ADS_PROPERTY_DELETE, "proxyAddresses", Array(strAddress)
		'objUser.PutEX ADS_PROPERTY_CLEAR, "proxyaddresses", 0 
	End If
Next

objUser.SetInfo

Wscript.echo "Done!"

I feed it a full distinguished name (e.g. 'CN=Some Account,OU=Service Accounts,DC=domain,DC=com) and it reads the proxyAddresses attribute. If I echo what I am looking for (strAddress) inside the If Left... command, it finds the rfax: addresses I want to kill. However, the objUser.PutEX ADS_PROPERTY_DELETE does not actually delete the addresses from the proxyAddresses attribute. If I error check after the SetInfo, there aren't any errors. As you can see, I tried the CLEAR parameter to test it and it works as expected, removes all values for the proxyAddresses attribute. What's wrong with DELETE that it won't actually delete anything? I am running this under a Domain Admin account so its not permissions.
 
Try this instead, note you only have to enter the username instead of having to get the distinguished name:

Code:
Const ADS_PROPERTY_DELETE = 4
strUser = InputBox("Enter the UserName:","Clean up rfax: addresses")

Set objUser = GetObject("LDAP://" & SearchDistinguishedName(userstring))

For Each strAddress In objUser.proxyAddresses
    If Left(strAddress,5) = "rfax:" Then
        objUser.PutEX ADS_PROPERTY_DELETE, "proxyAddresses", Array(strAddress)
        objUser.SetInfo
    End If
Next

Wscript.echo "Done!"

Public Function SearchDistinguishedName(ByVal vSAN)
    ' Function:     SearchDistinguishedName
    ' Description:  Searches the DistinguishedName for a given SamAccountName
    ' Parameters:   ByVal vSAN - The SamAccountName to search
    ' Returns:      The DistinguishedName Name
    Dim oRootDSE, oConnection, oCommand, oRecordSet

    Set oRootDSE = GetObject("LDAP://rootDSE")
    Set oConnection = CreateObject("ADODB.Connection")
    oConnection.Open "Provider=ADsDSOObject;"
    Set oCommand = CreateObject("ADODB.Command")
    oCommand.ActiveConnection = oConnection
    oCommand.CommandText = "<LDAP://" & oRootDSE.get("defaultNamingContext") & _
        ">;(&(objectCategory=User)(samAccountName=" & vSAN & "));distinguishedName;subtree"
    Set oRecordSet = oCommand.Execute
    On Error Resume Next
    SearchDistinguishedName = oRecordSet.Fields("DistinguishedName")
    On Error GoTo 0
    oConnection.Close
    Set oRecordSet = Nothing
    Set oCommand = Nothing
    Set oConnection = Nothing
    Set oRootDSE = Nothing

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Mark, I'd replace this:
SearchDistinguishedName(userstring)
with this:
SearchDistinguishedName(strUser)

shinedog:
I think the trick is to call the SetInfo method inside the loop.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV, bad cut and paste on my part.

I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
Work SMARTER not HARDER. The Spider's Parlor's Admin Script Pack is a collection of Administrative scripts designed to make IT Administration easier! Save time, get more work done, get the Admin Script Pack.
 
Yeah I tried calling the SetInfo in the loop and it still did the same thing, wouldn't delete anything. The SetInfo works outside the loop for the CLEAR so I think it should for the DELETE also. I'm assuming I can go through the proxyAddresses array once and mark the ones I'm looking for as deleted and then SetInfo once to write the changes back rather than writing the changes after each address. It's excruciating long doing the SetInfo after each address.

My original problem is that we have literally thousands of these bad rfax: addresses on several accounts and I was trying to purge them as they are causing the AD object to exceed the max size resulting in replication issues. I think the script was actually working but the replication issues kept reverting the object back as I have related errors in the event viewer. I need to confirm by doing it to an object with just a few addresses.

Thanks for the info on flipping it over to the user name, I was gonna flip it over to that once I fixed my original project. You just saved me some time! :D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top