Solved

DIRECTORY SERVICES -Filter an ADSI Attribute

Posted on 2014-03-06
2
370 Views
Last Modified: 2014-04-14
(Exchange 2010)

Hello all,
My goal is to locate all the employees in the company and add an Exchange Custom Attribute.  Now the only field that identifies the user as an employee is in ADSI Edit, which was updated thru a Schema change.  

When I run the following cmd below in EMS, it appears to complete but does not not add 'Employee' to EMC Custom Attribute4


$Searcher = New-Object -Typename DirectoryServices.DirectorySearcher ($domain = [ADSI]"")
$Searcher.filter = "(&(objectClass=user)(HRPro=TRUE))"
$userResult = $Searcher.findall()
$Empl = $userResult
<#

######################################
$Empl | Foreach{
      $Entry = $_.GetDirectoryEntry()
      $DN = ($Entry.DistinguishedName).ToString()
      $scriptpath = ($Entry.scriptpath).ToString()
      Set-Mailbox $DN -CustomAttribute4 “Employee”}
#>

0
Comment
Question by:GJohn32
  • 2
2 Comments
 
LVL 1

Author Comment

by:GJohn32
ID: 39910496
If I run a partial cmd, it does work and provides me with the number of employees that have TRUE in ADSIEdit.  I'm not sure how to connect both cmds where I can retrieve the employees and add the custom attribute in EMC.


$Searcher = New-Object -Typename DirectoryServices.DirectorySearcher ($domain = [ADSI]"")
$Searcher.filter = "(&(objectClass=user)(HRPro=TRUE))"
$userResult = $Searcher.findall()
$userResult.count
0
 
LVL 1

Accepted Solution

by:
GJohn32 earned 0 total points
ID: 40000186
correct script

$Searcher = New-Object -Typename DirectoryServices.DirectorySearcher ($domain = [ADSI]"")
$Searcher.filter = "(&(objectClass=user)(HRPro=TRUE))"
$userResult = $Searcher.findall()
$employeeList =@()
$userResult |
      ForEach-Object      {
            $directoryEntry = $_.GetDirectoryEntry()

            $user = new-object Object
            $user | add-Member Noteproperty SamAccountName $directoryEntry.SamAccountName.ToString()
            $user | add-Member Noteproperty omiOracleHRProvision $directoryEntry.omiOracleHRProvision.ToString()
            $user | add-Member Noteproperty EmployeeType $directoryEntry.employeeType.ToString()
            $user | add-Member Noteproperty Department $directoryEntry.Department.ToString()
            $user | add-Member Noteproperty Company $directoryEntry.Company.ToString()
            $user | add-Member Noteproperty extensionAttribute4 $directoryEntry.extensionAttribute4.ToString()
            $employeeList += $user

            $directoryEntry.Put( 'extensionAttribute4', 'Employee' )
            $directoryEntry.SetInfo()                                
      }
      
$employeeList |
      Export-CSV .\xxxx
0

Featured Post

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Read this checklist to learn more about the 15 things you should never include in an email signature.
The following article is intended as a guide to using PowerShell as a more versatile and reliable form of application detection in SCCM.
In this video we show how to create a Contact in Exchange 2013. We show this process by using the Exchange Admin Center. Log into Exchange Admin Center.: First we need to log into the Exchange Admin Center. Navigate to the Recipients >> Contact ta…
To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

831 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