Solved

DIRECTORY SERVICES -Filter an ADSI Attribute

Posted on 2014-03-06
2
378 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
If you troubleshoot Outlook for clients, you may want to know a bit more about the OST file before doing your next job. IMAP can cause a lot of drama if removed in the accounts without backing up.
In this video we show how to create an Accepted Domain 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 Mail Flow >> Ac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

622 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