Domino LDAP and export-csv

This topic contains 0 replies, has 1 voice, and was last updated by Profile photo of Forums Archives Forums Archives 5 years, 3 months ago.

  • Author
  • #6188

    by dosteroid at 2012-10-11 01:10:52

    Hi all

    Im really new to Powershell, but in my company we needed to retrieve some information from Domino Directory (address book) containing uid, firstname, lastname, maildomain and mail... So I search accross the Internet hoping to find a solution and Im nearly there, but I also need to export it to a csv file and thats where it gets tricky for me, since I get a message saying: cmdlet Export-csv at command pipeline position 1. Supply values for the following parameters: InputObject:

    My code looks like this:
    #Create the connection

    $Connection = New-Object -Com "ADODB.Connection"
    $Connection.Provider = "ADsDSOObject"
    $Connection.Open("Active Directory Provider")
    $Command = New-Object -Com "ADODB.Command"
    $Command.ActiveConnection = $Connection

    #Create the Query

    $Query = "SELECT uid,mail,maildomain FROM " + `
    "'LDAP://" + `
    "'WHERE ObjectClass='inetOrgPerson'"

    #Execute the command

    $Command.CommandText = $Query
    $Execution = $Command.Execute()
    $Execution.fields | ? {$ -eq "uid"} | select Value
    $Execution.fields | ? {$ -eq "mail"} | select Value
    $Execution.fields | ? {$ -eq "maildomain"} | select Value

    do{$Execution.fields; $Execution.movenext()}

    export-csv c:\dominodir.csv -NoTypeInformation

    The output of the export-csv should be like this:

    uid | mail | maildomain
    john | | domainname

    Any Help would be greatly appreciated


    by Klaas at 2012-10-11 02:40:48

    I have no idea how to work with Domino, so I can't tell if there's a better way to extract the data.

    export-csv needs objects to export, so you can either include it in a loop (but then each passage would overwrite the previous export and you would end up with only the last record),
    or you can give the object collection as a parameter (that's what the message asks for) or you can deliver objects through the pipeline.

    Maybe ...
    $Execution = $Command.Execute()
    $Execution | export-csv c:\dominodir.csv -NoTypeInformation

    does the trick?

    by dosteroid at 2012-10-11 05:32:31

    Hmm that does give me a csv file and no inputObject, but with a lot different content than I would have thought:

    Properties AbsolutePosition ActiveConnection BOF Bookmark CacheSize CursorType EOF Fields LockType MaxRecords RecordCount Source AbsolutePage EditMode Filter PageCount PageSize Sort Status State CursorLocation MarshalOptions DataSource ActiveCommand StayInSync DataMember Index
    System.__ComObject 1 System.__ComObject FALSE 0 1 3 FALSE System.__ComObject 1 0 959 SELECT uid,mail,maildomain FROM 'LDAP://'WHERE ObjectClass='inetOrgPerson' 1 0 0 96 10 0 1 2 0 System.__ComObject System.__ComObject TRUE

    Nothing that looks like the intended uid, mail, maildomain.

    Any ideas anyone?


    by dosteroid at 2012-10-11 05:33:33

    And by the way I only changed the following:

    #Execute the command

    $Command.CommandText = $Query
    $Execution = $Command.Execute()
    $Execution | export-csv c:\dominodir.csv -NoTypeInformation
    $Execution.fields | ? {$ -eq "uid"} | select Value
    $Execution.fields | ? {$ -eq "mail"} | select Value
    $Execution.fields | ? {$ -eq "maildomain"} | select Value

    by Klaas at 2012-10-11 06:20:35

    I thought $Execution would contain a rowset.
    The purpose is to have a collection of objects. The pipe to export-csv would then be the last statement of the script.

    In your script as it is, [quote="dosteroid"]$Execution.fields | ? {$ -eq "uid"} | select Value
    $Execution.fields | ? {$ -eq "mail"} | select Value
    $Execution.fields | ? {$ -eq "maildomain"} | select Value[/quote]
    and [quote="dosteroid"]do{$Execution.fields; $Execution.movenext()}[/quote] will both write fields to the shell and there it ends; they are not collected nor piped through.
    Since I can't reproduce your query myself I'm not sure how to put it in the pipeline. As an alternative you could add each row to an array. After the loop you should end with either $YourArray | export-csv c:\dominodir.csv -NoTypeInformation
    Export-csv -inputobject $YourArray -path c:\dominodir.csv -NoTypeInformation

    by dosteroid at 2012-10-11 13:14:33

    Tried to solve this, but it too complicated for me Im afraid... not the experienced with Powershell as I wrote in the beginning 🙁

    I don't know what how to put the array together and after that loop through it using the values I have in my script :/


You must be logged in to reply to this topic.