Solved

Powershell - size limit error

Posted on 2013-10-22
8
2,572 Views
Last Modified: 2013-10-22
Hi EE

SubSun helped me with the script below that compares members of two groups . It works great on small groups but if they are over a certain amount which I dont know .. I get the error below .. the groups I am trying to compare have 20k users .

Any ideas what I need to modify ?

Function Compare-Member ($Source,$Group) {
      $DN = (Get-AdGroup $Source).DistinguishedName
      "Working on group $Group"
      $result = Get-ADGroupMember $Group | % {
      If (!(Get-ADUser $_.SamAccountName -properties memberOf |
            ? {$_.memberOf -Match $DN})){$_.SamAccountName}
      }
      If ($result){
      "Missing Members"
      $result
      }
      Else{
      "All NUIDs Match !"
      }
}

Compare-Member Test_1 TEST_4


ERROR below ..

PS E:\Projects\Groups> .\CompareABGroups.ps1
Working on group TEST_4
Get-ADGroupMember : The size limit for this request was exceeded
At E:\Projects\Groups\CompareABGroups.ps1:5 char:12
+     $result = Get-ADGroupMember $Group | % {
+               ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (TEST_4:ADGroup) [Get-ADGroupMember], ADException
    + FullyQualifiedErrorId : The size limit for this request was exceeded,Microsoft.ActiveDirectory.Management.Commands.GetADGroupMember
0
Comment
Question by:MilesLogan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 40

Expert Comment

by:Subsun
ID: 39592383
How many members you have in the group is it above 5000?
0
 
LVL 37

Expert Comment

by:Neil Russell
ID: 39592389
0
 
LVL 2

Author Comment

by:MilesLogan
ID: 39592444
Hi Subsun .. yes .. both groups have over 5000
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 40

Expert Comment

by:Subsun
ID: 39592485
Try to replace Get-ADGroupMember $Group

With
Get-ADGroup $Group -Properties Members | Select-Object -ExpandProperty Members | Get-ADObject | ?{$_.ObjectClass -eq "user"}

Open in new window


Function Compare-Member ($Source,$Group) {
      $DN = (Get-AdGroup $Source).DistinguishedName
      "Working on group $Group"
      $result = Get-ADGroup $Group -Properties Members | 
		Select-Object -ExpandProperty Members | 
			Get-ADObject | 
				?{$_.ObjectClass -eq "user"} | % {
      If (!(Get-ADUser $_.SamAccountName -properties memberOf |
            ? {$_.memberOf -Match $DN})){$_.SamAccountName}
      }
      If ($result){
      "Missing Members"
      $result
      }
      Else{
      "All NUIDs Match !"
      }
}

Open in new window

0
 
LVL 2

Author Comment

by:MilesLogan
ID: 39592561
Hi SubSun

I received the error below .

Get-ADUser : Cannot validate argument on parameter 'Identity'. The argument is null. Supply a non-null argument and try the command again.
At E:\Projects\groups\CompareABGroups.ps1:8 char:24
+       If (!(Get-ADUser $_.SamAccountName -properties memberOf |
+                        ~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Get-ADUser], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.GetADUser
0
 
LVL 40

Expert Comment

by:Subsun
ID: 39592582
In line 8 change Get-ADUser $_.SamAccountName

to

Get-ADUser $_.DistinguishedName
0
 
LVL 40

Accepted Solution

by:
Subsun earned 500 total points
ID: 39592586
Or try...
Function Compare-Member ($Source,$Group) {
      $DN = (Get-AdGroup $Source).DistinguishedName
      "Working on group $Group"
      $result = Get-ADGroup $Group -Properties Members | 
		Select-Object -ExpandProperty Members | 
			Get-ADObject -properties Samaccountname | 
				?{$_.ObjectClass -eq "user"} | % {
      If (!(Get-ADUser $_.SamAccountName -properties memberOf |
            ? {$_.memberOf -Match $DN})){$_.SamAccountName}
      }
      If ($result){
      "Missing Members"
      $result
      }
      Else{
      "All NUIDs Match !"
      }
}

Open in new window

0
 
LVL 2

Author Closing Comment

by:MilesLogan
ID: 39592870
That was it ! thank you !
0

Featured Post

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Active Directory permissions 5 46
is a device online 4 46
Moving database to a shared server 7 38
Export Active Directory Members from a Group 15 21
A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
A company’s centralized system that manages user data, security, and distributed resources is often a focus of criminal attention. Active Directory (AD) is no exception. In truth, it’s even more likely to be targeted due to the number of companies …
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question