Solved

DIRECTORY SERVICES -Filter an ADSI Attribute

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
how to add IIS SMTP to handle application/Scanner relays into office 365.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

732 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