I extract with my script the users of my active directory
Import-Module ActiveDirectory
Get-ADUser -Filter * -properties * | Select SAMaccountname, givenname, surname, DistinguishedName | Export-Csv c: \ users \ administrator \ desktop \ users.csv -notypeinformation -Encoding UTF8
In this script I use the DistinguishedName command which returns the CN, the OU and the DC. My goal is to keep only the first OU and delete the rest when creating the .csv.
Example of what the script returns:
"SAMaccountname","givenname","surname","DistinguishedName"
"Jean-Yves.R","Jean-Yves","Raymond","CN=Jean-Yves Raymond,OU=Communication,OU=Direction Générale,OU=Elan & Co,OU=Domain Controllers,DC=ELAN-G1,DC=local"
Example of what I want:
"SAMaccountname","givenname","surname","DistinguishedName"
"Jean-Yves.R","Jean-Yves","Raymond","Communication"
TY :)
-properties *. It is horribly slow since it returns everything, even the non indexed properties, and you are only using the properties returned by default anyways. It is not needed. If you do need more properties just ask for the ones you want.-Properties employeeid