Active Directory Export via PowerShell (Displayname & EmployeeID) Using Get-ADUser
<p>I want to export list all AD User Accounts with just employeeid attribute form my domain where I want to exclude a particular OU -- want to exclude all of them.
Here is the script I ran, but did not work no luck
BTW must be non-null Employee IDattribute</p>

<pre><code>$OUDN = "OU=Service Accounts,OU=Accounts,DC=domain,DC=tld"
Get-ADUser -Properties mail |select name,samaccountname,mail,manager,department,employeeid -Filter {Enabled -eq $true} | Where-Object { $_.DistinguishedName -notlike "*,$OUDN" }
</code></pre>

<p>Other Code:</p>

<pre><code>$OUDN = "OU=Service Accounts,OU=Accounts,DC=domain,DC=tld"
    Get-ADUser -properties CN,Title,samaccountname,mail,displayname,manager,department,distinguishedname,employeeid  | select-object CN,Title,employeeid,mail,@{n=”PRODID”;e=”samaccountname”},DisplayName,@{n=”Manager Name”;e={(Get-ADuser -identity $_.Manager -properties displayname).DisplayName}},@{n=”ManagerID”;e={(Get-ADuser -identity $_.Manager –properties samaccountname).samaccountname}},Department -Filter {Enabled -eq $true} | Where-Object { $_.DistinguishedName -notlike "*,$OUDN" }
</code></pre>