Format Output of Get-QADUser

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

  • Author
    Posts
  • #6312

    by charliek at 2013-03-31 21:51:10

    My Mission] Get a list of ALL the groups for a list of users and output the list in a specific delimited format.

    I found the following script that works...except that it is not in the format that I need.


    $FilePath = "c:\temp\output.csv"
    Import-Csv c:\temp\users.csv |
    Get-QADUser -Identity {$_.user} -SizeLimit 0 | Select-Object name, sAMAccountName, @{Name="Groups";Expression={(Get-QADMemberOf $_ | Select-Object -expandProperty Name) -join ";"}} | export-csv $FilePath

    Questions (Where I need help)]

    1) How can I get the output to look something like this:

    user 1, group1
    user 1, group2
    user 1, group3
    user 2, group1
    user 2, group3
    user 3, group4
    user 3, group5

    2) How might I incorportate the status (enabled/disabled) of the account into the report? It might look like this:

    user 1, Enables, group1
    user 1, Enabled, group2
    user 1, Enabled, group3
    user 2, Disabled, group1
    user 2, Disabled, group3
    user 3, Enabled, group4
    user 3, Enabled, group5

    Your help is very much appreciated! I've spent many hours on what is likely a very simple issue.

    by poshoholic at 2013-04-01 06:26:35

    Here's a sample (untested) script that should give you what you are after, or at least get you closer to the destination:
    $FilePath = "c:\temp\output.csv"
    Import-Csv c:\temp\users.csv |
    Get-QADUser -Identity {$_.user} -SizeLimit 0 | ForEach-Object {
    foreach ($group in Get-QADMemberOf $_) {
    $_ | Select-Object -Property Name,SamAccountName,Enabled,@{Name='Group';Expression={$group.Name}}
    }
    } | export-csv $FilePath

    by charliek at 2013-04-01 11:44:40

    Perfect! Many Many Many Thanks.

    by charliek at 2013-04-05 20:12:50

    Any pointers on how I might be able to extend the script below to include the description and notes for each group?

    $FilePath = "c:\temp\output.csv"
    Import-Csv c:\temp\users.csv |
    Get-QADUser -Identity {$_.user} -SizeLimit 0 | ForEach-Object {
    foreach ($group in Get-QADMemberOf $_) {
    $_ | Select-Object -Property Name,SamAccountName,@{Name='Group';Expression={$group.Name}}
    }
    } | export-csv $FilePath

    by ArtB0514 at 2013-04-08 09:03:53

    How about something like this:
    $FilePath = "c:\temp\output.csv"
    $UserData = @()
    Import-Csv c:\temp\users.csv |
    Get-QADUser -Identity {$_.user} -SizeLimit 0 | ForEach-Object {
    $UserData += New-Object PSObject @{
    'Name' = $_.Name
    'SamAccountName' = $_.SamAccountName
    'Description' = $_.Description
    'Notes' = $_.Notes
    'Group' = ($_.AllMemberOf | foreach {($_.Split(','))[0].Substring(3)}) -join "`n"
    }
    }
    $UserData | Select name,SamAccountName,Description,Notes,Group | export-csv $FilePath -NoTypeInformation

You must be logged in to reply to this topic.