We help IT Professionals succeed at work.

Clear the Notes for all users in an Ou. How can i do it in one shot. ADS

Hi,

Clear the Notes for all users in an Ou. How can i do it in one shot.
Any script of a inbuilt way of doing this.

Regards
sharath
Comment
Watch Question

I think you posted the same question and answer had been provide to you , ref the post below,
http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_23751755.html

Author

Commented:
Yes but this time i cannot use the tool. Need a script or a inbuilt way of doing this...
this tool is strictly prohibited now... :-(
tigermattSite Reliability Engineer
Most Valuable Expert 2011

Commented:

Sharath,

Should hopefully be self-explanatory!

It's a shame you can't use ADModify.Net. Did the big bosses ban it? The same happened on several of my networks.

-Matt

strContainer = "OU=Domain Administrators,OU=User Accounts,OU=MyNetwork,DC=company,DC=com" 'The OU to traverse looking for User Account objects
strVal = "" 'The value to set the Notes field to
 
 
 
Set objContainer = GetObject("LDAP://" & strContainer)
 
 
For Each objUserAcct In objContainer
	If objUserAcct.Class="user" Then
		objUserAcct.Put "info", strVal
		objUserAcct.SetInfo
	End If
Next

Open in new window

tigermattSite Reliability Engineer
Most Valuable Expert 2011

Commented:

On second thoughts use the below.

-Matthew

		on error resume next
strContainer = "OU=Domain Administrators,OU=User Accounts,OU=MyNetwork,DC=company,DC=com" 'The OU to traverse looking for User Account objects
strVal = " " 'The value to set the Notes field to
 
Set objContainer = GetObject("LDAP://" & strContainer)
 
If strVal = "" Then strVal = " "
 
For Each objUserAcct In objContainer
	
        If objUserAcct.Class="user" Then
                objUserAcct.Put "info", strVal
                objUserAcct.SetInfo
        End If
Next

Open in new window

rejoinderManager, IT
Top Expert 2008
Commented:
This script will clear the info field and make the value = NULL
strContainer = "OU=Domain Administrators,OU=User Accounts,OU=MyNetwork,DC=company,DC=com"
Set objContainer = GetObject("LDAP://" & strContainer)
For Each objUserAcct In objContainer
    If objUserAcct.Class="user" Then
        objUserAcct.PutEx 1, "info", vbNullString
        objUserAcct.SetInfo
    End If
Next

Open in new window

tigermattSite Reliability Engineer
Most Valuable Expert 2011

Commented:
Rejoinder- I don't really see much difference between my and your scripts? Was it necessary to repeat?
rejoinderManager, IT
Top Expert 2008

Commented:
The biggest difference is yours makes the field = " " while mine makes it Null.  If your script is used and down the road Sharath decides to run another script to populate the notes field and keeps the notes field in tact, there would be a space on the first line.
tigermattSite Reliability Engineer
Most Valuable Expert 2011

Commented:

Fair enough :)

Author

Commented:
Matthew the script runs but the data is cleared from Notes

Rejoinder i get this error.

---------------------------
Windows Script Host
---------------------------
Script:      C:\Clear all Notes in an OU.vbs
Line:      2
Char:      1
Error:      A referral was returned from the server.
Code:      8007202B
Source:       (null)

---------------------------
OK  
---------------------------

Author

Commented:
Matthew the script runs but the data is cleared from Notes

Rejoinder i get this error.

---------------------------
Windows Script Host
---------------------------
Script:      C:\Clear all Notes in an OU.vbs
Line:      2
Char:      1
Error:      A referral was returned from the server.
Code:      8007202B
Source:       (null)

---------------------------
OK  
---------------------------
tigermattSite Reliability Engineer
Most Valuable Expert 2011

Commented:

Sharath,

I thought the whole idea of this was to remove all the data from the Notes field?

Using my script, you are able to specify a value in one of the variables at the top for what you want the data in the notes field to be replaced with. At present, it is blank, but you can enter some data there should you wish.

-Matt

Author

Commented:
I want to empty the whole data what ever is there
tigermattSite Reliability Engineer
Most Valuable Expert 2011

Commented:

So is the below script not working for you? It searches all users in the specified OU and empties their Notes field.

-Matthew
                on error resume next
strContainer = "OU=Domain Administrators,OU=User Accounts,OU=MyNetwork,DC=company,DC=com" 'The OU to traverse looking for User Account objects
strVal = "" 'The value to set the Notes field to (leave blank to clear the field)
 
Set objContainer = GetObject("LDAP://" & strContainer)
 
If strVal = "" Then strVal = vbNullString
 
For Each objUserAcct In objContainer
        
        If objUserAcct.Class="user" Then
                objUserAcct.Put "info", strVal
                objUserAcct.SetInfo
        End If
Next

Open in new window

Author

Commented:
No it does not clear

Author

Commented:
No it does not clear
tigermattSite Reliability Engineer
Most Valuable Expert 2011

Commented:

OK I've just tested it and it is an issue with the code. Try the below.

Essentially you CANNOT set (through ADSI Scripting) the Notes field either to vbNullString or to a "" value. The only option to clear the data is to set the Notes field to a single space, which the script is now set to do. This means Rejoinder's code will not work either.

-Matt
'                on error resume next
strContainer = "OU=Functional Accounts,OU=Users,OU=GJB,DC=GJB,DC=Bawden" 'The OU to traverse looking for User Account objects
strVal = "" 'The value to set the Notes field to (leave blank to clear the field)
 
Set objContainer = GetObject("LDAP://" & strContainer)
 
If strVal = "" Then strVal = " "
 
For Each objUserAcct In objContainer
        
        If objUserAcct.Class="user" Then
                objUserAcct.Put "info", strVal
                objUserAcct.SetInfo
        End If
Next

Open in new window

Author

Commented:
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Clear all Notes in an OU.vbs
Line:      5
Char:      1
Error:      A referral was returned from the server.
Code:      8007202B
Source:       (null)

---------------------------
OK  
---------------------------

Author

Commented:
I get this

---------------------------
Windows Script Host
---------------------------
Script:      C:\Clear all Notes in an OU.vbs
Line:      5
Char:      1
Error:      A referral was returned from the server.
Code:      8007202B
Source:       (null)

---------------------------
OK  
---------------------------
tigermattSite Reliability Engineer
Most Valuable Expert 2011

Commented:

That would usually indicate an issue with the OU path you've entered, rather than a VBScript issue. Can you check the OU path is correct (no spaces in the wrong place etc.)?

Author

Commented:
The OU path is perfect as i have many scripts with the same path. It is just copy and paste

Author

Commented:
The OU path is perfect as i have many scripts with the same path. It is just copy and paste
tigermattSite Reliability Engineer
Most Valuable Expert 2011

Commented:

Can you post the OU path here for me (so I can create it in my AD structure and test)?

Author

Commented:
Here it is
                on error resume next
strContainer = "OU=Named Accounts,OU=User Accounts,OU=IND,OU=Countries,dc=development,dc=co,dc=uk" 'The OU to traverse looking for User Account objects
strVal = "" 'The value to set the Notes field to (leave blank to clear the field)
 
Set objContainer = GetObject("LDAP://" & strContainer)
 
If strVal = "" Then strVal = " "
 
For Each objUserAcct In objContainer
        
        If objUserAcct.Class="user" Then
                objUserAcct.Put "info", strVal
                objUserAcct.SetInfo
        End If
Next

Open in new window

Author

Commented:
Here it is
                on error resume next
strContainer = "OU=Named Accounts,OU=User Accounts,OU=IND,OU=Countries,dc=development,dc=co,dc=uk" 'The OU to traverse looking for User Account objects
strVal = "" 'The value to set the Notes field to (leave blank to clear the field)
 
Set objContainer = GetObject("LDAP://" & strContainer)
 
If strVal = "" Then strVal = " "
 
For Each objUserAcct In objContainer
        
        If objUserAcct.Class="user" Then
                objUserAcct.Put "info", strVal
                objUserAcct.SetInfo
        End If
Next

Open in new window

tigermattSite Reliability Engineer
Most Valuable Expert 2011

Commented:

I have just tested it, and it seems to be working here, so I'm not quite sure exactly where the problem is. It's not something like you need a dc=group between dc=development and dc=co (of course I don't know your directory structure so just looking at other scripts you have posted and comparing!)?

-Matthew

Author

Commented:
Is this because i have 6 + lines of data...

I even tried with just 1 Ou and some users withoutt that long OU structure
tigermattSite Reliability Engineer
Most Valuable Expert 2011

Commented:

Sorry, Sharath: I'm still not too sure exactly where the problem is. I've just copied several lines of data into a user account, run the script, and it has cleared it out again, so it can't be an issue with having multiple lines.

This might be an ADSIEdit job - if you launch adsiedit.msc on the server, then go and find the OU you want the script to search for users in. Right-click the OU, then press Properties. Click on the 'distinguishedName' entry in the 'Attribute' column, then press the View button. You should be able to highlight, right-click on it and then copy the data out. Can you paste exactly what you see there here in a comment?

Author

Commented:
Shall do when i am back in the morining into my Domain.... I seriously need to thing about my VPN now... :-))
tigermattSite Reliability Engineer
Most Valuable Expert 2011

Commented:

:-) No problem

rejoinderManager, IT
Top Expert 2008

Commented:
I was able to recreate the error message - there is something wrong with the DC section of the OU path.  Can you please check each OU path in AD and double check the domain name area as was mentioned above.  Lastly, if there are spaces in the OU's themselves, please make sure there are not two spaces side-by-side which could be there but difficult to see.

And for the record, the vbNullString is valid and will work, I promise and have tested this out!
Site Reliability Engineer
Most Valuable Expert 2011
Commented:

rejoinder,

You must be doing something different to me, I have tried on several occasions from various servers and vbNullString always produces an 80005008 error.

However I did manage to get it working using ADS_PROPERTY_CLEAR and the PutEx function, so Sharath, try the one below which doesn't use a space to clear the data :-)

-Matt
Const ADS_PROPERTY_CLEAR = 1
                'on error resume next
strContainer = "ou=domain admins,ou=london,ou=areas,ou=users,ou=managed,ou=company,dc=company,dc=co,dc=uk" 'The OU to traverse looking for User Account objects
 
Set objContainer = GetObject("LDAP://" & strContainer)
 
For Each objUserAcct In objContainer
        
        If objUserAcct.Class="user" Then
                objUserAcct.PutEx ADS_PROPERTY_CLEAR, "info", 0
                objUserAcct.SetInfo
        End If
Next

Open in new window

rejoinderManager, IT
Top Expert 2008

Commented:
I'm crossing my fingers  :-)

Guess we will know more Monday.

Author

Commented:
Sorry Guys its my mistake. I expected it to replicate immediately as it used to update the details into the notes in Min. I expected the same speed. When i ran it this morning it took 1 + hrs to remove all data and i tried both the scripts and worked perfect...

Sorry for my wrong assumption that it did not work...

Author

Commented:
Sorry Guys its my mistake. I expected it to replicate immediately as it used to update the details into the notes in Min. I expected the same speed. When i ran it this morning it took 1 + hrs to remove all data and i tried both the scripts and worked perfect...

Sorry for my wrong assumption that it did not work...
tigermattSite Reliability Engineer
Most Valuable Expert 2011

Commented:

If you're removing a large amount of data from the 'Notes' fields then I guess it definitely would take quite a while to replicate.

Glad it's working now, thanks Sharath :-)

-Matthew

Author

Commented:
Thanks a lot to you both for the patient help...