Solved

DIRECTORY SERVICES -Filter an ADSI Attribute

Posted on 2014-03-06
2
364 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Utilizing an array to gracefully append to a list of EmailAddresses
Marketers need statistics and metrics like everybody else needs oxygen. In this article we explain how to enable marketing campaign statistics for Microsoft Exchange mail.
In this video we show how to create a mailbox database 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 Servers >> Data…
The video tutorial explains the basics of the Exchange server Database Availability groups. The components of this video include: 1. Automatic Failover 2. Failover Clustering 3. Active Manager

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now