Solved

DIRECTORY SERVICES -Filter an ADSI Attribute

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

Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Save Exchange PowerShell Command 12 34
Fraud Email 22 76
Chocolatey with PowerShell is not working again 2 34
exchange 2007 9 13
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
In-place Upgrading Dirsync to Azure AD Connect
The basic steps you have just learned will be implemented in this video. The basic steps are shown to configure an Exchange DAG in a live working Exchange Server Environment and manage the same (Exchange Server 2010 Software is used in a Windows Ser…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

756 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