Информация о члене группы AD - PullRequest
0 голосов
/ 25 сентября 2018

Скрипт ниже, когда в списке участников более 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 }
...