See if this works for you. It's a bit more complicated, but you only have to change the $BaseGroup value and the keys/values in the $GroupToColumn has to make it work for any group name to whatever column name you want in the result.
$BaseGroup = 'GroupX'
# keys are group names, values are column names
$GroupToColumn = @{
'GroupA' = 'SDZ-MSAccess2010'
'GroupB' = 'SDZ-MSAccess2003'
'GroupC' = 'SDZ-MSOffice2010'
}
# create the hash used to build the PSCustomObject
$GroupNames = [string[]]($GroupToColumn.Keys)
$h = [ordered]@{
User = ""
}
$GroupNames |
Sort-Object |
ForEach-Object{
$h[$GroupToColumn[$_]] = $false
}
# Get each user that's a member of the base group
get-adgroupmember $BaseGroup |
Select-Object -Expand samaccountname |
ForEach-Object{
# Get this user's group membership
$h.User = $_ # put the samaccount into the hash
# set each group's "presence" in hash to $false
$GroupNames |
ForEach-Object{
$h[$GroupToColumn[$_]] = $false
}
Get-ADPrincipalGroupMembership $_ | # get the users group membership -- Should this use -RECURSE???
ForEach-Object{
if ($GroupNames -contains $_.name){
$h[$GroupToColumn[$_.name]] = $true
}
}
[PSCustomObject]$h
}