Link to home
Start Free TrialLog in
Avatar of Sybux
SybuxFlag for Switzerland

asked on

Export LDAP information to CSV with powershell

Hello,

I'm trying to create a little script to export some information of my ldap to a CSV file.

I'm using this little script :
$strFilter = "((objectCategory=User))"

$objDomain = New-Object System.DirectoryServices.DirectoryEntry("LDAP://OU=Utilisateurs,DC=myldap")
$objSearcher = New-Object System.DirectoryServices.DirectorySearcher
$objSearcher.SearchRoot = $objDomain
$objSearcher.PageSize = 10
$objSearcher.Filter = $strFilter
$objSearcher.SearchScope = "Subtree"

$colProplist = "name","postofficebox"
foreach ($i in $colPropList){$objSearcher.PropertiesToLoad.Add($i)}

$colResults = $objSearcher.FindAll()

$myList = @()
foreach ($objResult in $colResults) {
    $objItem = $objResult.Properties
    $myUSer = "" | Select-Object Name, PostOfficeBox
    $myUser.Name = $objResult.Properties["name"]
    $myUser.PostOfficeBox = $objResult.Properties["postofficebox"]
    $myList += $myUser
}
    

Open in new window


but when I export $mylist to csv, I get only the object type and not the value as you can see :
#TYPE Selected.System.String
"Name","PostOfficeBox"
"System.DirectoryServices.ResultPropertyValueCollection","System.DirectoryServices.ResultPropertyValueCollection"

Open in new window


I running it for a quite long time and I can get out where I'm wrong.
Any help should be very welcome.
ASKER CERTIFIED SOLUTION
Avatar of Jamie McKillop
Jamie McKillop
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial