Book Image

Active Directory with PowerShell

By : Pamarthi Venkata Sitaram, YELLAPRAGADA U PADMAVATHI
5 (1)
Book Image

Active Directory with PowerShell

5 (1)
By: Pamarthi Venkata Sitaram, YELLAPRAGADA U PADMAVATHI

Overview of this book

If you are looking to automate repetitive tasks in Active Directory management using the PowerShell module, then this book is for you. Any experience in PowerShell would be an added advantage.
Table of Contents (11 chapters)
10
Index

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) ...