广告组成员信息

时间:2018-09-25 03:59:23

标签: active-directory powershell-v3.0

以下脚本,当成员列表超过2000个条件不起作用时。你能在这方面检查并帮助我吗

Import-Module ActiveDirectory
$Path = Get-Location
$GroupName = Read-Host "Give me the GROUP NAME to check the members `t "
$MemberCount = (Get-ADGroup $GroupName -Properties Member | Select-Object -Expand Member).Count

    Write-Host "`t Group Name `t`t`t: $GroupName" -BackgroundColor DarkRed
    Write-host "`n`t Total Users/Groups added :$MemberCount" -BackgroundColor DarkRed

     if($MemberCount -le 50) { $ReadText = Read-Host "`n`nDo you want this information to save (y/n)"
     if($ReadText -eq 'y') {write-host "`nInformation writing to the Text file .... " -ForegroundColor Yellow
       Get-ADGroupMember $GroupName | select Name >GroupDetails.txt
       write-host "`nFile saved to $path\GroupDetails.txt (same location from where you are running the script)" -ForegroundColor Green  }
   if($ReadText -eq 'n') {
       Write-host "`nGroup members are listing below " -ForegroundColor Yellow
       Get-ADGroupmember $GroupName | select Name   }}

  elseif($MemberCount -ge 50 -and $MemberCount -le 2000){
        $Choice = Read-Host "`n`nDo you want to SAVE this information (y/n) "

        if($Choice -eq 'n'){ write-host "`n`n`t!!!! Bye Bye !!!!!" -BackgroundColor DarkMagenta  }
        if($Choice -eq 'y'){ $ReadOption = Read-host "`nWhich format you need your Output - Text(t) or CSV(c)"
         if($ReadOption -eq 't'){write-host "`nInformation SAVING to the Text file .... " -ForegroundColor Yellow
         Get-ADGroupMember $Groupname | select Name >GroupDetails.txt
         write-host "`nFile saved to $path\GroupDetails.txt (same location from where you are running the script)" -ForegroundColor Green  }
         if($ReadOption -eq 'c'){ write-host "`nInformation SAVING to the CSV file .... " -ForegroundColor Yellow
            Get-ADGroupMember $Groupname | select Name >GroupDetails.csv
             write-host "`nFile saved to $path\GroupDetails.csv (same location from where you are running the script)" -ForegroundColor Green }}

 if($MemberCount -gt 2000 -and $MemberCount -le 100000)

 {   foreach ($group in $GroupName) {$users = @{}
      Get-ADUser -Filter '*' -Property Name, DisplayName | ForEach-Object { $users[$_.DistinguishedName] = $_ }
        $Info = Get-ADGroup $group -Properties Member | Select-Object -Expand Member | ForEach-Object { if ($users.ContainsKey($_)) {$users[$_]}
      else {  Write-host "`nUnknown DN/Groups: ${_}"} 
                   }} }
                $Info | Export-Csv $Path\new.csv }

0 个答案:

没有答案