Hi All,
I have been using a script for some time now to grab all the groups a user is a member of in AD, as well as details of the group in question. It works fine and I have managed to adjust it to accept a custom object as input and spit out Microsoft.ActiveDirectory.Management.ADGroup objects as a result.
The issue I have is if my input object contains more then one user I can not differentiate the results from one user to the next and ideally would like to create an object that can be used again later. I believe I can resolve this by creating a custom object as the ouput which lists the user, domain and then group objects I receive but I am unsure how to go about this.
[pre]
Function Get-AllADGroups ()
{
[cmdletBinding()]
Param
(
[Parameter(ValueFromPipelineByPropertyName, Position=0, Mandatory=$true)]
[string]$Identity,
[Parameter(ValueFromPipelineByPropertyName, Position=1, Mandatory=$false)]
[string]$Server= “my.domain.com”
)
process
{
#Write-Output “User is: $Identity”
#Write-Output “Domain is: $Server”
foreach ($Group in (Get-ADPrincipalGroupMembership -Identity $Identity -Server $Server | Select-Object name))
{
Get-ADGroup -Identity $Group.name -Server $Server -Properties * #| Select-Object name, description
}
#Write-Output “”
}
}
#Below code is to create an example of the in going custom object
$test = @([pscustomobject]@{Identity=“User1”;Server=“my.domain.com”},
[pscustomobject]@{Identity=“User1”;Server=“my.domain2.com”},
[pscustomobject]@{Identity=“User2”;Server=“my.domain.com”},
[pscustomobject]@{Identity=“User2”;Server=“my.domain2.com”})
$test
[/pre]