POWERSHELL AD USER WITH GROUP:

AD USER WITH GROUP:
PROCONS:
1. user does not list if only in Domain user,
2.outpu shows for the disabled user also.

ipmo activedirectory
$searchBase = "DC=pugazh,dc=co,DC=in"
$userlist = Get-ADUser -Filter * -SearchBase $searchBase -Properties memberOf
$report = @()
Foreach ($user in $userlist)
{
    $name = $user.Name
    $SAM = $user.SAMAccountName
    $memberOf = $user.memberOf
    $i = 0 #if you only want the user and SAMAccountName to appear once you will need a counter like this, it'se easier to just display it on every row
    Foreach($Group in $memberOf)
    {
        $GroupName = $Group.Replace('CN=','')
        $rowGroup = $GroupName -replace ",.*"
        if($i -eq 0)
        {
            $rowName = $name
            $rowSAM = $SAM
        }
        else
        {
            $rowName = ""
            $rowSAM = ""
        }
        $objRow = New-Object System.Object
        $objRow | Add-Member -MemberType NoteProperty -Name Name -Value $rowName
        $objRow | Add-Member -MemberType NoteProperty -Name SAMAccountName -Value $rowSAM
        $objRow | Add-Member -MemberType NoteProperty -Name GroupName -Value $rowGroup
        $report += $objRow
        $i++
    }}
$report | ft

Comments

Popular posts from this blog

Troubleshooting Netlogon Error Codes

Service Principal Names (SPNs) SetSPN Syntax (Setspn.exe)

Troubleshooting AD Active Directory Replication Error 8456 or 8457: "The source | destination server is currently rejecting replication requests"