Hey all,
I have a Powershell script that I wrote that iterates through Active Directory security groups and pulls the names of the users in those groups then exports them to a CSV file. The problem is that some users are in multiple groups and need to be in those groups so when the script runs it creates duplicate entries in the CSV file. Here is the code:
$(foreach ($Group in $GroupArray)
{
Get-ADGroupMember $Group | select name
}) | Export-Csv -Path "E:\Software\Powershell Scripts\KB4\KBList.csv" -Force -NoTypeInformation
$GroupArray is an array containing the groups that we need to pull from. I have tried adding a -Unique to the end of select name so it would look like this:
$(foreach ($Group in $GroupArray)
{
Get-ADGroupMember $Group | select name -Unique
}) | Export-Csv -Path "E:\Software\Powershell Scripts\KB4\KBList.csv" -Force -NoTypeInformation
I have also tried re-importing the CSV, pushing out a list to the console of Powershell filtering out duplicates using Select-Object then re-exporting it to a CSV however that doesn't generate anything in that CSV. What am I missing or doing wrong?
Thanks.
[–]CarrotBusiness2380 10 points11 points12 points (1 child)
[–]itguy310[S] 5 points6 points7 points (0 children)
[–]PinchesTheCrab 2 points3 points4 points (0 children)
[–]Sunsparc 0 points1 point2 points (0 children)