Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

Get AD Groups and Group Members for specific groups

$
0
0

In AD I have groups for different companies.  I have already exported the groups for the specific company to a text file using the command:

Get-ADGroup -filter {samaccountname -like "*companyname*"} |select name | Format-Table -HideTableHeaders | out-file c:\groups.txt

That command works fine, however, I have looked up a few ways to grab that file and use the group name to create a list that get-adgroupmember will grab each group name and export the group name as well as the users in the group to a CSV file.

get-content c:\groups.txt | get-adgroupmember | ExportTo-CSV

or

get-adgroupmember {get-content c:\groups.txt} | ExportTo-CSV

I'm not to worried about sort order or selecting just the name field just yet, I just want to get my code to play well for me.  I'm thinking that I'd rather have it in XML since it would allow me to tab out users under each group.

As an example I want my end output to look like this

GroupName1

     User1

     User2

     User3

GroupName2

    User1

    User4

    User12

etc...

Can anyone help me get this working?

Thanks in advance.


Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>