Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Powershell - size limit error

Posted on 2013-10-22
8
Medium Priority
?
2,968 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
  • 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
New Tabletop Appliances Blow Competitors Away!

WatchGuard’s new T15, T35 and T55 tabletop UTMs provide the highest-performing security inspection in their class, allowing users at small offices, home offices and distributed enterprises to experience blazing-fast Internet speeds without sacrificing enterprise-grade security.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
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 to another domain controller. Log onto the new domain controller with a user account t…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

972 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