Created
March 26, 2014 18:53
-
-
Save iqwirty/9790628 to your computer and use it in GitHub Desktop.
Show group membership in Excel for each group listed in an array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# 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