I am trying to script a report and am struggling with a certain section.
In my code below, $groupmembership is an array but I need that array to be entered into a single entry or cell in the resulting csv file. I tried doing a join with a carriage return but the output I’m getting looks like {@{name=user1}, @{name=user2}, @{name=user3} and then it truncates. I’m assuming the way I used join is joining the array heading, ‘name’ to each line of the array.
I know its got to be something simple I’m missing or forgetting but I just cant figure it out. Any guidance would be appreciated.
$rootshare = Get-ChildItem -Directory -Path "\\server\share"
$output = @()
For($i = 1; $i -le $rootshare.Count; $i++){
Write-Progress -Activity "Gathering Permissions" -PercentComplete ($i/$rootshare.Count*100)
foreach($share in $rootshare){
$acl = Get-Acl -Path $share.FullName
foreach($access in $acl.Access){
$secgroup = ($access.IdentityReference).ToString()
$secgroup = $secgroup.Substring(10)
$groupmembership = (Get-ADGroupMember -Identity $secgroup -Recursive | select name) -join "`n"
$properties = [ordered]@{'This Share'=$share.FullName;'Grants these rights'=$Access.FileSystemRights;'To these groups'=$Access.IdentityReference;'Which consists of these members'=$groupmembership}
$output += New-Object -TypeName PSObject -Property $Properties
}
}
}
$output | Out-GridView