PowerShell: Exportar lista de grupos para qual um determinado usuário pertence (MemberOf)

Olá pessoal,
Segue script aonde podemos utilizar para saber quais grupos um determinado usuário pertence (MemberOf).

    Simple script to produce a listing of user's group memberships
    Script will create a simple listing of a user's group memberships.
    Output is in object format so you can use other Powershell cmdlet's
    with the output, such as Export-CSV, Out-File, ConvertTo-HTML, etc.
    Groups are presented using the friendly name, and are sorted
    Name of the user you want to list
    PSObject    User Name
                Group Name
    .Get-UserGroupMembership.ps1 -User thesurlyadmin
    List all of the groups for "thesurlyadmin"
    Author:            Martin Pugh
    Twitter:           @thesurlyadm1n
    Spiceworks:        Martin9700
    Blog:              www.thesurlyadmin.com
       1.0             Initial Release
Param (
Begin {
    Try { Import-Module ActiveDirectory -ErrorAction Stop }
    Catch { Write-Host "Unable to load Active Directory module, is RSAT installed?"; Break }
Process {
    ForEach ($U in $User)
    {   $UN = Get-ADUser $U -Properties MemberOf
        $Groups = ForEach ($Group in ($UN.MemberOf))
        {   (Get-ADGroup $Group).Name
        $Groups = $Groups | Sort
        ForEach ($Group in $Groups)
        {   New-Object PSObject -Property @{
                Name = $UN.Name
                Group = $Group
Comando no PowerShell
.Get-UserGroupMembership.ps1 username | Export-Csv c:scriptsusername.txt
Até a próxima,
Marco Antonio (Mada)