<#
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
}
}
}
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
本文转自 bilinyee博客,原文链接: http://blog.51cto.com/ericfu/1905602 如需转载请自行联系原作者