<#
This script can be used to list group members for Walmart SH
Formart can be easy transfored
Date:2017-03-09
#>
Set-Content c:\temp\Groups.txt -Value "Group Name,Group Members“
$groups = Get-ADGroup -filter * -SearchBase "OU=yyyy,DC=ccc,DC=bbb,DC=com"
ForEach ($g in $groups) {
if ($g.Name -like "S0XXXX_FS*") {
$g1= -Join ($g.Name,", ")
Add-Content -Path "c:\temp\Groups.txt" -Value $g1
write-host $g1
$onegroup = [ADSI] "LDAP:// $g"
foreach ($member in $onegroup.member)
{
$Uname = new-object directoryservices.directoryentry("LDAP://$member")
$u1 = -Join (" ,", $Uname.cn)
Add-Content -Path "c:\temp\Groups.txt" -Value $u1
write-host $u1
}
}
}
import-csv c:\temp\Groups.txt -delimiter "," | export-csv c:\temp\GroupDetails.csv
时间: 2024-10-12 22:24:43