Page 1 of 1 1
Topic Options
#92232 - 2003-06-23 07:09 AM How do you create blank fields with ADSI on AD
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
I ran accross this the other day and so far have not found a solution.
I'm sure it can easily be done once you know the correct syntax or method.

I had a lot of accounts in the Active Directory that had some invalid data on their ProfilePath

It is easy to query or update data on the Active Directory, but I could not figure out how to delete the entry and leave it blank.

Example:





$UserGroup = GetObject('LDAP://etc...')
for each $user in $UserGroup
if $user.class = "user"
if NOT $user.profilePath =""
? 'Profile path for '+$user.name+ 'is not blank - it is: '+$user.profilepath
$user.profilePath=""
$user.SetInfo
endif
endif
next




The user profile will not be set to blank.

I can run this code and it works fine.






$UserGroup = GetObject('LDAP://etc...')
for each $user in $UserGroup
if $user.class = "user"
if NOT $user.profilePath =""
? 'Profile path for '+$user.name+ 'is not blank - it is: '+$user.profilepath
$user.profilePath="Anything I want it to be except BLANK"
$user.SetInfo
endif
endif
next




I found this to be true for other fields as well, which leads me to believe that there must be some special syntax, or method to accomplish a BLANK entry or Delete (without replacing) and entry.

You can create/delete to have a BLANK entry with the GUI tools, so I know it can be done.

Does anyone know the proper method to BLANK/DELETE an entry?

Top
#92233 - 2003-06-24 12:52 AM Re: How do you create blank fields with ADSI on AD
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
You are correct DOC. See this post http://aspn.activestate.com/ASPN/Mail/Message/1276204 for some details on how to accomplish what you want.

If have any trouble, let me know and I will translate it for you this evening when I have more time.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#92234 - 2003-06-23 05:36 PM Re: How do you create blank fields with ADSI on AD
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Thanks Howard,

I'll wait for a translation [Wink]

Would appear you're using Win32 calls to accomplish, which would lead me to believe that it is more like a WMI call.

I'll wait till later though for an explanation on the matter.

Top
#92235 - 2003-06-23 07:44 PM Re: How do you create blank fields with ADSI on AD
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
I think I have it now Howard.

Seems you have to use the "description name" on the forms along with the putEX and the
$ADS_PROPERTY_CLEAR = 1

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/netdir/adsi/modifying_attributes_with_adsi.asp

quote:
ADS_PROPERTY_CLEAR = 1
ADS_PROPERTY_UPDATE = 2
ADS_PROPERTY_APPEND = 3
ADS_PROPERTY_DELETE = 4

ADS_PROPERTY_CLEAR
Instructs the directory service to remove all the property value(s) from the object.

ADS_PROPERTY_UPDATE
Instructs the directory service to replace the current value with the element(s) in the passed VARIANT array.

ADS_PROPERTY_APPEND
Instructs the directory service to append the new value(s) to the existing one(s).

ADS_PROPERTY_DELETE
Instructs the directory service to delete the specified value(s) of a property.

This code works.


$ADS_PROPERTY_CLEAR = 1
$user = GetObject('LDAP://etc....')
if $user.class = "user"
? 'User name is: '+$user.samaccountname
? 'Profile path currently is: '+$user.profilepath
$user.PutEX ($ADS_PROPERTY_CLEAR, "profilepath",'')
$user.SetInfo
? 'Profile path is now: '+$user.profilepath
endif

Top
#92236 - 2003-06-23 08:15 PM Re: How do you create blank fields with ADSI on AD
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
Doc, I was just going to post a translation for you. You beat me to it.

Oh, well. At least I can help you with the Filter. Take a peek at this...



Dim $sFilter[0$sFilter[0]="User"
$UserGroup = GetObject('LDAP://blah...')
$UserGroup.Filter = $sFilter
For Each $User in $UserGroup
    If Not $User.profilePath =""
      'Old ProfilePath for '+$User.Name+': '+$User.profilePath+"*" ?
      $user.PutEx (1,"profilePath","")
      ;$user.profilePath="test"
      $user.SetInfo
      'New ProfilePath for '+$User.Name+': '+$User.profilePath+"*" ?
    EndIf
Next



[ 23. June 2003, 20:28: Message edited by: Chris S. ]

Top
#92237 - 2003-06-23 10:05 PM Re: How do you create blank fields with ADSI on AD
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11628
Loc: CA
Chris,

Thanks for the feedback on the Filtering. I did some further testing where we had about 15,000 objects in one OU.

The $user.class type of filtering took about 15 seconds to to return 67 objects out of the 15,000

Using your filtering method it returned the same 67 objects in just over 2 seconds. [Eek!]

Top
#92238 - 2003-07-23 03:40 PM Re: How do you create blank fields with ADSI on AD
Jason Gauthier Offline
Fresh Scripter

Registered: 2003-04-02
Posts: 10
Loc: Dayton, OH
Greetings! I don't mean to bump an old thread, but this is exactly what I was looking for to reset some of my data as well.

But, with one exception. I also need to empty out some arrays.

This is what I tried knowing that it wouldn't work.

For Each $Element In $user.msExchADCGlobalNames
If Not $Element =""
? $Element
$user.PutEx(1,$user.msExchADCGlobalNames,"")
? $User.Name + " ADCG cleared."
$user.Setinfo
endif
Next

I'm sure I'm close. Any ideas?

Thanks!

Top
#92239 - 2003-07-23 03:51 PM Re: How do you create blank fields with ADSI on AD
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Try:

$Element.PutEx(1,"msExchADCGlobalNames","")

You may have to perform a GetObject on each element before doing the PutEx and Setinfo.

[ 23. July 2003, 15:52: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#92240 - 2003-07-23 06:59 PM Re: How do you create blank fields with ADSI on AD
Jason Gauthier Offline
Fresh Scripter

Registered: 2003-04-02
Posts: 10
Loc: Dayton, OH
Doesn't seem to like that syntax:

For Each $Element In $user.msExchADCGlobalNames
If Not $Element =""
$Element.PutEx (1,"msExchADCGlobalNames","")
? $User.Name + " ADCG cleared."
$user.Setinfo/
endif
Next

Script error : unknown command !
$Element.PutEx(1,"msExchADCGlobalNames","")

Top
#92241 - 2003-07-23 07:03 PM Re: How do you create blank fields with ADSI on AD
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
Looking at your code closer I have to ask, why do
you have a for each loop?

what is you object? $user?

Please post your code from the GetObject call.
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#92242 - 2003-07-23 07:05 PM Re: How do you create blank fields with ADSI on AD
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
ms-Exch-ADC-Global-Names Attribute

--------------------------------------------------------------------------------

Caution It is not recommended that you modify this attribute.

Attribute Value
adminDescription ms-Exch-ADC-Global-Names
adminDisplayName ms-Exch-ADC-Global-Names
attributeID 1.2.840.113556.1.4.7000.102.63
attributeSyntax 2.5.5.12
isMemberOfPartialAttributeSet TRUE
isSingleValued FALSE
lDAPDisplayName msExchADCGlobalNames
cn ms-Exch-ADC-Global-Names
oMSyntax 64
objectCategory CN=Attribute-Schema,
objectClass attributeSchema
schemaIdGuid kPBikJOw0hGqBgDAT47t2A==
searchFlags 1
attributeSecurityGuid VAGN5Pi80RGHAgDAT7lgUA==
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#92243 - 2003-07-23 07:06 PM Re: How do you create blank fields with ADSI on AD
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
$user.PutEx(1,"msExchADCGlobalNames","")
$user.SetInfo
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#92244 - 2003-07-23 07:14 PM Re: How do you create blank fields with ADSI on AD
Jason Gauthier Offline
Fresh Scripter

Registered: 2003-04-02
Posts: 10
Loc: Dayton, OH
My whole code:

Dim $sFilter[0] $sFilter[0]="User"
$UserGroup = GetObject('LDAP://cn=Users,dc=xxx,dc=com')
$UserGroup.Filter = $sFilter
For Each $User in $UserGroup
If Not $User.msExchADC =""
$user.PutEx (1,"legacyExchangeDN","")
? $User.Name + " ExDN cleared."
$user.Setinfo
endif

If Not $User.mail =""
$user.PutEx (1,"mail","")
? $User.Name + " mail cleared."
$user.Setinfo
endif

For Each $Element In $user.msExchADCGlobalNames
If Not $Element =""
$user.PutEx(1,"msExchADCGlobalNames","")
? $User.Name + " ADCG cleared."
$user.Setinfo/
endif
Next

next

I'm trying to clean up a bad ADC replication, and I need to set msExchADCGlobalNames to empty.

Top
#92245 - 2003-07-23 07:16 PM Re: How do you create blank fields with ADSI on AD
Jason Gauthier Offline
Fresh Scripter

Registered: 2003-04-02
Posts: 10
Loc: Dayton, OH
My whole code:

Dim $sFilter[0] $sFilter[0]="User"
$UserGroup = GetObject('LDAP://cn=Users,dc=xxx,dc=com')
$UserGroup.Filter = $sFilter
For Each $User in $UserGroup
If Not $User.msExchADC =""
$user.PutEx (1,"legacyExchangeDN","")
? $User.Name + " ExDN cleared."
$user.Setinfo
endif

If Not $User.mail =""
$user.PutEx (1,"mail","")
? $User.Name + " mail cleared."
$user.Setinfo
endif

For Each $Element In $user.msExchADCGlobalNames
If Not $Element =""
$user.PutEx(1,"msExchADCGlobalNames","")
? $User.Name + " ADCG cleared."
$user.Setinfo
endif
Next

next

I'm trying to clean up a bad ADC replication, and I need to set msExchADCGlobalNames to empty.

Your last post worked, I'm testing again.

[ 23. July 2003, 19:20: Message edited by: Jason Gauthier ]

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 874 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.054 seconds in which 0.014 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org