Skip to content

Instantly share code, notes, and snippets.

@iqwirty
Created March 26, 2014 18:53
Show Gist options
  • Save iqwirty/9790628 to your computer and use it in GitHub Desktop.
Save iqwirty/9790628 to your computer and use it in GitHub Desktop.
Show group membership in Excel for each group listed in an array
#
# Get the group members for each group from an array, and export the member list
# to a .csv file. Then open all the .csv files in Excel.
#
Clear-Host
$outputFolder = "c:\tempo"
$groupList = @("Group1",
"Group2",
"Group3")
ForEach ($group in $groupList)
{
# Note the use of "{}" around the $group variable so PowerShell knows not to
# include the underscore as part of the variable name and replace it with
# an empty string.
$outputFileFullPath = "$outputFolder\${group}_$(Get-Date -Format yyyy-MM-dd_hh-mm-ss).csv"
Write-Host "Processing file '$outputFileFullPath'..."
Get-QADGroupMember $group | `
Sort LastName | `
Select LastName, FirstName, Name | `
Export-Csv -Path $outputFileFullPath -NoTypeInformation
Invoke-Item -Path $outputFileFullPath
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment