none
Format Powershell Output RRS feed

  • Question

  • hey everyone,

    I'm trying to run an OpenLdap query and I'm getting the desired output in powershell however would like to get that exported to a .csv/excel preferably.

    This is how the first few lines look like from the output-

    Enter LDAP Password: # extended LDIF
    #
    # LDAPv3
    # base <ou=Ext, ou=People> with scope subtree
    # filter: objectclass=*
    # requesting: displayname employeenumber mail city site status
    #

    # Ext, People
    dn: ou=Ext, ou=People

    # E25, ext, people, 
    dn: employeeNumber=E25, ou=ext, ou=people
    displayname: Gavin
    employeenumber: E25
    mail: Gavin@contoso.com
    city: External
    site: Chicago
    status: OBSOLETE

    # E26, ext, people, 
    dn: employeeNumber=E26, ou=ext, ou=people
    displayname: Ken
    employeenumber: E26
    mail: Ken@contoso.com
    city: External
    site: Sunnyvale
    status: Active

    I'm looking to get this formatted in such a way so I can get rid of the initial few lines & start with the actual ldap data in form of an .xlsx file with columns representing DisplayName, EmployeeNumber, Mail, City, Site & Status with all values under them.

    Any clue would be highly appreciated.

    Thanks in advance~~

    Wednesday, March 4, 2015 4:45 PM

Answers

  • If you want to use an external executable to run your query, then you are dependent on that executable's output. You will need to 1) change the executable's output format (if possible), 2) parse the output in some way, or 3) use a different tool to run your query that can produce output in the format you want.


    -- Bill Stewart [Bill_Stewart]


    Wednesday, March 4, 2015 7:31 PM
    Moderator

All replies

  • What script are you using to get this output?

    ¯\_(ツ)_/¯

    Wednesday, March 4, 2015 5:19 PM
  • I'm using ldapsearch.exe embedded in a .PS1. This was to see if there are native formatting options available.

    any other method to pull out such .csv/.xlsx will be really appreciated.

    Wednesday, March 4, 2015 7:26 PM
  • If you want to use an external executable to run your query, then you are dependent on that executable's output. You will need to 1) change the executable's output format (if possible), 2) parse the output in some way, or 3) use a different tool to run your query that can produce output in the format you want.


    -- Bill Stewart [Bill_Stewart]


    Wednesday, March 4, 2015 7:31 PM
    Moderator