This script first imports the Active Directory module, sets the output file path, and then gets all the AD groups using the Get-ADGroup cmdlet. It then loops through each group and gets its members using the Get-ADGroupMember cmdlet. Finally, it outputs the group and its members to the specified output file using the Add-Content cmdlet.
Note that you may need to modify the script to fit your specific environment, such as specifying a different output file path or filtering the groups to a specific organizational unit (OU).
You can read and copy the PowerShell script from below URL.
[ Ссылка ]
Ещё видео!