ndalmolin_13
asked on
Help generating a report from Powershell
Hello Powershell Experts,
I think I have asked a similar question in the past, but I can't find it. I have been tasked with finding all of the distribution groups in our domain and then getting a list of all the user in each group. The following Powershell code gets the results I want and displays them to the screen in the format that I want:
My question is how can I get this information into a text or CSV file?
I think I have asked a similar question in the past, but I can't find it. I have been tasked with finding all of the distribution groups in our domain and then getting a list of all the user in each group. The following Powershell code gets the results I want and displays them to the screen in the format that I want:
$DistributionGroups = get-adgroup -filter 'GroupCategory -eq "distribution"' | sort samaccountname
foreach ($DistributionGroup in $DistributionGroups)
{
Write-host $DistributionGroup.name
Write-Host "------------------------- ---------- ----"
Get-ADGroupMember -Identity $DistributionGroup.SamAcco untName | select name | sort name
Write-Host ""
}
foreach ($DistributionGroup in $DistributionGroups)
{
Write-host $DistributionGroup.name
Write-Host "-------------------------
Get-ADGroupMember -Identity $DistributionGroup.SamAcco
Write-Host ""
}
My question is how can I get this information into a text or CSV file?
Export to csv:
Get-ADGroup -Filter 'GroupCategory -eq "distribution"' |
Sort-Object -Property SamAccountName |
ForEach-Object {
$groupName = $_.Name
Get-ADGroupMember -Identity $_.SamAccountName |
Sort-Object -Property Name |
Select-Object -Property @{n='Group'; e={$groupName}}, Name
} | Export-Csv -NoTypeInformation -Path C:\Temp\distribution.csv
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help everyone.
Open in new window