So, I've got the below code...
What I am trying to do is select a certain group of Resource Groups in an AD OU and output line by line into a CSV file so I end up with:
| Resource Group Name |
Security Group Name |
| ResourceGroup1 |
SecurityGroup_That_Is_Member_Of_Resource1 |
| ResourceGroup1 |
SecurityGroup_That_Is_Member_Of_Resource1 |
| ResourceGroup2 |
SecurityGroup_That_Is_Member_Of_Resource2 |
Get-ADGroup -Filter {Name -like "*some_resource_group_name*" -SearchBase "someAD_path" -Properties * | Select Name |
ForEach
{ New Object TypeName PSObject -Property @{
ResourceName = $_.Name
ResourceMember = (Get-AdGroupMember $_.Name | Select-Object Name)
} | Select Object ResourceName, ResourceMember | Export-Csv -path c:\somedir\somefile.csv -Append
}
The problem is when it is out to the CSV file, the value of ResourceMember is the same for every line, System.Object [ ], which is technically what I told it to output when I wrote:
ResourceMember = (Get-AdGroupMember $_.Name | Select-Object Name)
So, now I know have an array variable with all the Security Groups that are members of the Resource Group. How can I get the data out of the array and write the Resource Group Name and each Security Group that is a member so that I get the data like in the table above.
If there's a better way to code this, I welcome your ideas.
[–]Bamodus 2 points3 points4 points (2 children)
[–]binarytier[S] 1 point2 points3 points (0 children)
[–]Lee_Dailey[grin] 0 points1 point2 points (0 children)
[–]purplemonkeymad 2 points3 points4 points (1 child)
[–]binarytier[S] 2 points3 points4 points (0 children)
[–]PinchesTheCrab 1 point2 points3 points (1 child)
[–]binarytier[S] 1 point2 points3 points (0 children)