Hello. Please bare with me as I am new to Powershell. After getting into it I can't believe that I haven't been using this longer! My problem is that I'm so far unsuccessful in writing a script that will list the members of multiple groups using Get-ADGroup. This is what my code looks like:
$ADgroups1=Get-ContentC:\Temp\ListofGroups1.txt
(
Get-ADGroup"$ADgroups1"-propertiesmembers).members |
Get-ADUser
-propertiesdisplayName,SamAccountName|Select-ObjectdisplayName,SamAccountName|
Out-File
-append-filepathC:\temp\multiplADgroupmembers.txt
This is the error I get when I use that:
Get-ADGroup : Cannot find an object with identity:
When I specify just one group then it works perfect. It looks like this:
$ADgroup1="Group Name" (Get-ADGroup-identity"$ADgroup1"-propertiesmembers).members | Get-ADUser -propertiesdisplayName,SamAccountName|Select-ObjectdisplayName,SamAccountName| Out-File -append-filepathC:\temp\multiplADgroupmembers.txt
Again, I want to retrieve users from multiple groups. I'd also like to be able to label them according to their groups if possible. I truly appreciate all your help as I am new to this and would appreciate recommendations in literature to get a beginner like me to be an expert like you :).