Solved

How do I delete the home address field (except the zipcode) from AD?

Posted on 2010-11-12
6
274 Views
Last Modified: 2012-05-11
I need to remove the home/work address field in AD but leave the zip code.  We don't want anyone except HR knowing the home addresses of our employees.  Is their a batch file or script that someone can help me with,
0
Comment
Question by:ITPULASKI
6 Comments
 
LVL 57

Expert Comment

by:Mike Kline
ID: 34121534
If you look at this page  http://www.selfadsi.org/user-attributes-w2k3.htm

Are you trying to delete streetaddresss or everything on that tab except for postal code?
0
 

Author Comment

by:ITPULASKI
ID: 34121564
I am trying to delete Street, P.O. Box, City, State/Province except zip which shows up on the 'Address' tab on a user profile in AD.
0
 

Accepted Solution

by:
ITPULASKI earned 0 total points
ID: 34124234
I was able to find a way to delete a single user with this script:

Const ADS_PROPERTY_CLEAR = 1

Set objUser = GetObject _
   ("LDAP://cn=johns smith,ou=contractors,ou=stlouis,dc=axi,dc=aic,dc=com")
 
objUser.PutEx ADS_PROPERTY_CLEAR, "streetAddress", 0
objUser.PutEx ADS_PROPERTY_CLEAR, "postofficebox", 0
objUser.PutEx ADS_PROPERTY_CLEAR, "l", 0
objUser.PutEx ADS_PROPERTY_CLEAR, "st", 0
objUser.PutEx ADS_PROPERTY_CLEAR, "c", 0
objUser.SetInfo

However, I am need to be able to delete multiplle users address information within an OU and I do not know how to do that.  Does anyone?
0
 
LVL 11

Expert Comment

by:Tasmant
ID: 34943182
You can use this code.
On Error Resume Next
Const ADS_PROPERTY_CLEAR = 1

strOU = "LDAP://OU=MyOU,DC=domain,DC=com"
'Set rootDSE = GetObject("LDAP://RootDSE")
'strDomain = "LDAP://" & rootDSE.Get("defaultNamingContext")

strfilter = "(&(objectCategory=Person)(objectClass=User))"
strAttributes = "adspath"
strScope = "onelevel"

Set objConnection = CreateObject("ADODB.Connection")
Set objcommand = CreateObject("ADODB.Command")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
objcommand.ActiveConnection = objConnection

objCommand.Properties("Page Size") = 1000
objCommand.Properties("Timeout") = 600
objCommand.Properties("Cache Results") = True

'Execute Query
objCommand.CommandText = "<" & strOU & ">;" & strFilter & ";" & strAttributes & ";" & strScope
Set objRecordSet = objCommand.Execute

Do Until objRecordSet.EOF
	Set objUser = GetObject(objRecordSet.Fields("adspath").Value)
		objUser.PutEx ADS_PROPERTY_CLEAR, "streetAddress", 0
		objUser.PutEx ADS_PROPERTY_CLEAR, "postofficebox", 0
		objUser.PutEx ADS_PROPERTY_CLEAR, "l", 0
		objUser.PutEx ADS_PROPERTY_CLEAR, "st", 0
		objUser.PutEx ADS_PROPERTY_CLEAR, "c", 0
		objUser.SetInfo
    objRecordSet.MoveNext
Loop

Open in new window

0
 
LVL 59

Expert Comment

by:Darius Ghassem
ID: 34959222
This question has been classified as abandoned and is being closed as part of the Cleanup Program. See my comment at the end of the question for more details.
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to install and use the NTBackup utility that comes with Windows Server.
This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
This tutorial will walk an individual through locating and launching the BEUtility application and how to execute it on the appropriate database. Log onto the server running the Backup Exec database. In a larger environment, this would generally be …
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question