Based on Oleg…err @Olaf’s code, try something like this:
$OU = "OU=test,DC=domain,DC=local"
Get-ADUser -Filter {MemberOf -like 'dfs_share1_*'} -Properties memberof -SearchBase $OU | #Find only users that are a member of the group
ForEach-Object {
[PSCustomObject]@{
User = $_.sAMAccountName
Groups = ($user.memberof | Where{$_.MemberOf -like 'dfs_share1_*') -join ',' #Show only the groups that you care about
}
}
Now that you write it in a single line … of course it cannot work. MemberOf is supposed to be an array. Try this:
$OU = “OU=test,DC=domain,DC=local”
Get-ADUser -Filter * -Properties memberof -SearchBase $OU | #Find only users that are a member of the group
ForEach-Object {
[PSCustomObject]@{
User = $.sAMAccountName
Groups = ($.memberof | Where-Object{$_ -like ‘dfs_share1_*’}) -join ‘,’ #Show only the groups that you care about
}
}
BTW: You are allowed to use our suggestions and use it for your own research and play with it to make it run.
When you create a new post you use the “Text” view, you insert the code you want, then you select the code and click on the code tag “PRE” - that’s all.