Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Powershell - size limit error

Posted on 2013-10-22
8
Medium Priority
?
2,847 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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
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 2000 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

Are You Ready for GDPR?

With the GDPR deadline set for May 25, 2018, many organizations are ill-prepared due to uncertainty about the criteria for compliance. According to a recent WatchGuard survey, a staggering 37% of respondents don't even know if their organization needs to comply with GDPR. Do you?

Question has a verified solution.

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

In this post we will be converting StringData saved within a text file into a hash table. This can be further used in a PowerShell script for replacing settings that are dynamic in nature from environment to environment.
A bad practice commonly found during an account life cycle is to set its password to an initial, insecure password. The Password Reset Tool was developed to make the password reset process easier and more secure.
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

688 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