locked
Format output csv RRS feed

  • Question

  • I am looking to format the output of my csv, my code is below:

    Get-ADUser -Filter {department -like "*"} -Properties * |Select-Object givenname, surname, department, emailaddress, office, manager |Export-Csv "c:\test.csv"

    Output:  John, Doe, Department, email@domain, Office, CN=John Manager,OU=user,DC=domain,DC=local

    I would like to strip out the domain objects in the output of manager and just have John Manager show, how could I do this please? 

    Thursday, April 11, 2019 7:37 PM

Answers

  • # use of calculated properties
    $properties = @(
        'givenname', 
        'surname',
        'department', 
        'emailaddress', 
        'office', 
        @{ n = 'manager'; e = { (Get-ADUser $_.manager).Name } }
    )
    Get-ADUser -Filter { department -like "*" } -Properties * |
        Select-Object $properties | 
        Export-Csv c:\test.csv
    


    \_(ツ)_/

    • Marked as answer by Uintas Thursday, April 11, 2019 8:04 PM
    Thursday, April 11, 2019 7:47 PM

All replies

  • # use of calculated properties
    $properties = @(
        'givenname', 
        'surname',
        'department', 
        'emailaddress', 
        'office', 
        @{ n = 'manager'; e = { (Get-ADUser $_.manager).Name } }
    )
    Get-ADUser -Filter { department -like "*" } -Properties * |
        Select-Object $properties | 
        Export-Csv c:\test.csv
    


    \_(ツ)_/

    • Marked as answer by Uintas Thursday, April 11, 2019 8:04 PM
    Thursday, April 11, 2019 7:47 PM
  • Thanks, that works
    Thursday, April 11, 2019 8:04 PM