Exporting an AD group member's details to CSV
Often, end users enquire about the membership of a particular group or list of groups. It is the job of Windows administrators to help them with the information in a format that is most suitable for them. We generally share such information in Excel (or CSV format). But this CSV preparation is not an easy task if there are nested members, and the number of groups you want to generate this report for are more. The function discussed in the following code can help here. It takes a list of group names as input and exports the membership details to a CSV file. At the time of export, we can choose whether to export direct members only or nested members as well:
Function Export-ADGroupMembers { [CmdletBinding()] Param( [Parameter(Mandatory=$true)] [String[]]$GroupName, [Switch]$Nested ) $MemArray = @() foreach($Group in $GroupName) { try { $GroupMem = @(Get-ADGroupMember -Identity $Group - Recursive:$Nested -EA Stop) if(!$GroupMem) ...