makanzore
asked on
Powershell find users DistinguishedName
Hello,
i need to find users DN with a csv liste of users name. So i have they's name and i want to find the DN. I have to do the LDAP root search becacause users are not on the same OU. This is my script but it dont work.
$ldapQuery=new-object directoryservices.director yentry("LD AP://dc=md l,dc=activ e")
$UserDetails=Import-Csv "C:\user1.csv"
$userdetails = $ldapQuery.psbase.Children
foreach($UD in $UserDetails)
{
$CN=$UD.CN
$accts=$ldapQuery.psbase.C hildren.Fi nd("cn=$CN ")
$accts.distinguishedName
}
my CSV file:
UserDetails
user1
user2
user3
Thank for your Help
i need to find users DN with a csv liste of users name. So i have they's name and i want to find the DN. I have to do the LDAP root search becacause users are not on the same OU. This is my script but it dont work.
$ldapQuery=new-object directoryservices.director
$UserDetails=Import-Csv "C:\user1.csv"
$userdetails = $ldapQuery.psbase.Children
foreach($UD in $UserDetails)
{
$CN=$UD.CN
$accts=$ldapQuery.psbase.C
$accts.distinguishedName
}
my CSV file:
UserDetails
user1
user2
user3
Thank for your Help
ASKER
Thanks for your answer
I download quest script to use the command get-QAduer but i got an error:
Get-QADUser : Impossible de valider l'argument sur le paramètre « Identity ». L'argument est null ou vide. Indiquez un
argument qui n'est pas null ou vide et réessayez.
Au niveau de ligne : 1 Caractère : 43
+ Import-CSV "C:\user1.csv" | %{ Get-QADUser <<<< $_.CN | Select-Object DN }
+ CategoryInfo : InvalidData: (:) [Get-QADUser], ParameterBindingValidation Exception
+ FullyQualifiedErrorId : ParameterArgumentValidatio nError,Que st.ActiveR oles.ArsPo werShellSn apIn.Power shell.Cmdl et
s.GetUserCmdlet
Thanks
I download quest script to use the command get-QAduer but i got an error:
Get-QADUser : Impossible de valider l'argument sur le paramètre « Identity ». L'argument est null ou vide. Indiquez un
argument qui n'est pas null ou vide et réessayez.
Au niveau de ligne : 1 Caractère : 43
+ Import-CSV "C:\user1.csv" | %{ Get-QADUser <<<< $_.CN | Select-Object DN }
+ CategoryInfo : InvalidData: (:) [Get-QADUser], ParameterBindingValidation
+ FullyQualifiedErrorId : ParameterArgumentValidatio
s.GetUserCmdlet
Thanks
ASKER
And with the command
========================== ========== ========
Import-Csv "C:\user1.csv" | %{
$Searcher = New-Object `
DirectoryServices.Director ySearcher( $Null, "(&(objectClass=user)(obje ctCategory =person)(c n=$($_.CN) ))")
$Searcher.FindAll() | Select-Object @{n='DistinguishedName';e= { $_.Properties["distinguish edname"] }}
}
========================== ========== ======
I got this error:
Une erreur s'est produite lors de l'énumération parmi une collection : The (&(objectClass=user)(objec tCategory= person)
cn=)) search filter is invalid..
Au niveau de ligne : 4 Caractère : 3
+ <<<< $Searcher.FindAll() | Select-Object @{n='DistinguishedName';e= { $_.Properties["distinguish edname"] }}
+ CategoryInfo : InvalidOperation: (System.Director...sultsEn umerator:R esultsEnum erator) [], RuntimeExcep
tion
+ FullyQualifiedErrorId : BadEnumeration
==========================
Import-Csv "C:\user1.csv" | %{
$Searcher = New-Object `
DirectoryServices.Director
$Searcher.FindAll() | Select-Object @{n='DistinguishedName';e=
}
==========================
I got this error:
Une erreur s'est produite lors de l'énumération parmi une collection : The (&(objectClass=user)(objec
cn=)) search filter is invalid..
Au niveau de ligne : 4 Caractère : 3
+ <<<< $Searcher.FindAll() | Select-Object @{n='DistinguishedName';e=
+ CategoryInfo : InvalidOperation: (System.Director...sultsEn
tion
+ FullyQualifiedErrorId : BadEnumeration
Can you show me what you have in that CSV file? Including the header line (if any).
Thanks,
Chris
ASKER
This is the CSV file i use header line and users:
UserDetails
user1
user2
user3
Thanks
UserDetails
user1
user2
user3
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Ok it works
Excuse me i didn't understand
Thanks for all
Excuse me i didn't understand
Thanks for all
Hey,
Searching will be required if you don't know where they are. There's Name Translate as well, but it might just be easier to use the Directory Searcher.
You'd have an easier time of this with the Quest CmdLets:
http://www.quest.com/powershell/
It makes it much shorter:
Import-CSV "C:\user1.csv" | %{ Get-QADUser $_.CN | Select-Object DN }
Chris
Open in new window