list the users name in specific OU+ the Groups

I need to write a Powershell Skript to list the users name in specific OU+ the Groups in which the user belongs to (but i need to list specific Group and not to see all Groups).

Ex : OU : A

Users under OU A

they are Member to the Groups X Y Z …

i have found this one :

Get-ADUser -Filter * -Properties samaccountname,memberof,description -SearchBase “OU” |

foreach {

$sam = $.samaccountname
$description = $
.description

foreach ($group in $_.memberof) {

New-Object PSObject -Property @{

  UserName = $_.samaccountname;
  Desc = $_.description
  
 Group = ($group -split ",")[0].Substring(3) 

}

}

} |select username,Desc,Group

But it will list all Groups to the user and i want to show all users and thier Groups (but not all Groups just y x)

I want to list all user name in OU A and the Groups (but i want to see just Group y x)
Can Some one help me please ?

Thanks

Go to Source
Author: Adam2020