Getting AD groups of user and exporting to csv RRS feed

  • Question

  • Hi,

    So I am trying to run an AD export at work using powershell 5.

    The way I am currently doing this, all of the AD group info of the user does not export on the same line in a different column however it spits the info out below the user. as I am using export csv at the end, it is essential that the adgroups appear next to the corresponding user and not below so filters in excel can be applied.

    For example instead of appearing like this

    name       title         manager         city

    John        Dev         Dave               London




    I'd like them to appear in a csv like this...

    name       title         manager         city            Groups

    John        Dev         Dave               London       App-ctx-snow-sg


    Your help would be appreciated

    #Importing required modules
    Import-Module ActiveDirectory
    #Setting variables
    $domain = $env:userdomain
    $date = get-date
    $fromemail = ********
    $reportresultsfile = 
    #Creating variable from composition file
    $compfile = import-csv C:\Scripts\ADExport-Meena\testcomp.csv
    $userarray = $compfile.samaccount
    #Gathering required infomration
    $userarray | ForEach-Object { 
    Get-ADUser -Identity $_ -Properties * | Select-Object name, department, city, title, homedirectory, organisation, memberof (Get-ADPrincipalGroupMembership $_ | select name)
    Get-ADPrincipalGroupMembership -Identity $_ | select name
    } | Format-Table -AutoSize -wrap 
    #Outputting information to a CSV file

    • Moved by Bill_Stewart Wednesday, December 12, 2018 9:46 PM This is not "scripts on demand"
    Friday, September 14, 2018 12:03 PM

All replies

  • You cannot export dissimilar object to the same CSV,

    Look in Gallery for scripts that can do what you area asking.


    Friday, September 14, 2018 12:13 PM