AD group report with Name, emailid, samaccount

AD group report with Name, email id, samaccount

Working for me:

(Get-ADGroup "Test1" -properties members).members |
Get-ADUser -properties displayName | Select-Object displayName,SamAccountName,emailaddress | export-CSV c:\users\administrator\File-Name.csv

#User full cmd: (Get-ADGroup -Identity Test1 -Properties members).members


Not works:
1.
Get-ADGroupMember -identity "Group Name" -Recursive |
Where-Object { $_.objectClass -eq "User" } |
Get-ADUser -Properties Name,SamAccountName,emailaddress |
Select-Object Name,SamAccountName,emailaddress | export-CSV c:\File-Name.csv

---
2.
$ADGroupName = "YourADGroupName"
$InputPath= "c:\UserCAIs.txt"

$a = @(Get-ADGroup $ADGroupName -Properties Member | Select-Object -ExpandProperty Member)

ForEach ($member in $a)
{
 $SplitStep1 = ($Member -split ",",2)[0]
 $SplitStep2 = ($SplitStep1 -split "=",2)[1]
 $SplitStep2 = $SplitStep2 | out-file -Append $InputPath
}

ForEach ($value in (Get-Content $InputPath))
{
 $b = Get-ADUser -identity $value -properties Name,SamAccountName,emailaddress |
Select-Object Name,SamAccountName,emailaddress | export-CSV c:\$ADGroupName.csv

---
3.
Import-Module Activedirectory
[array]$Members=$null
GC groups.txt | % {
$Group = Get-ADGroup $_  -ErrorAction SilentlyContinue
If ($Group){
$members += Get-ADGroupMember $Group.Name | Get-aduser -Properties * |
Select @{L='GroupName';e={$Group.Name}},Name,Samaccountname,Enabled
 }
}
$Members | Select * | Export-Csv c:\output.csv -NoTypeInformation

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"