我在Active Directory或Power shell中没有太多专业知识,我需要提取所有用户以及属于1000多个安全组的详细信息.
我尝试过几种不同的在线PS脚本,但由于脚本需要很长时间才能完成(我在脚本运行3天后停止了脚本)
我也尝试使用SSIS分解组列表并一次运行100个组,但无济于事.
我正在使用以下第一个脚本来拉取组的成员和第二个脚本以拉出其余的用户详细信息
附:组和用户是来自多个子域的混合.
脚本1:
$groups = Get-Content c:\temp\Groups.txt
foreach($Group in $Groups) {
Get-ADGroupMember -Id $Group | select @{Expression= {$Group};Label="Group Name"},* | Export-CSV c:\temp\GroupsInfo.CSV - NoTypeInformation
}
脚本2:
$objForest = [System.DirectoryServices.ActiveDirectory.Forest]::GetCurrentForest()
$DomainList = @($objForest.Domains | Select-Object Name)
$Domains = $DomainList | foreach {$_.Name}
$Users = Import-CSV c:\users\public\users.csv
#Act on each domain
foreach($Domain in ($Domains))
{
Write-Host "Checking $Domain" -fore blue
Foreach($mail in ($Users.mail))
{
Get-ADUser -filter {mail -eq $mail} -Server $domain -properties mail | select mail,employeeID,title,department,name
Export-CSV c:\temp\MemberDetails.CSV -NoTypeInformation
}
}
最佳答案 针对拥有4300名成员的小组进行了此操作
花了几分钟
$groupname = <whatever your group name is>
$servername = <whatever domain your group is with>
$dns = get-adgroup $groupname -server $servername -Properties member | select -ExpandProperty member
$adobjects = @()
$objqry = {
param([string[]]$items)
function GetAdsiObj {
param($dn)
$item = [adsi]$("LDAP://$_")
$item.setinfo()
return $item
}
return $items | select @{n='adsiobj';e={ GetAdsiObj $_}} | `
select @{n='samaccountname';e={$_.adsiobj.properties.samaccountname[0]}}, `
@{n='name';e={$_.adsiobj.properties.name[0]}}, `
@{n='objectclass';e={$_.adsiobj.properties.objectclass[$_.properties.adsiobj.objectclass.count - 1]}}, `
@{n='dn';e={$_.adsiobj.path}}, `
@{n='useraccountcontrol';e={$_.adsiobj.useraccountcontrol[0]}}
}
$jobs = @()
for($i= 0; $i -lt $dns.Count;$i += 250){
$data = $dns[$i..$($i + 249)]
$jobs += Start-Job -ScriptBlock $objqry -ArgumentList (,$data)
}
$runningcount = {
param($j)
return $($j | ?{ $_.State -eq "Running" }).Count
}
$jobcount = $jobs.Count
while($(&$runningcount $jobs) -gt 0){
write-progress -activity "Processing members" -status "Progress:" `
-percentcomplete (($jobcount- $(&$runningcount $jobs))/$jobcount*100)
}
$responses = $jobs | Wait-Job | Receive-Job
$responses | %{ $adobjects += @($_) }
$adobjects