Solved

Powershell - size limit error

Posted on 2013-10-22
8
2,687 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

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

Group policies can be applied selectively to specific devices with the help of groups. Utilising this, it is possible to phase-in group policies, over a period of time, by randomly adding non-members user or computers at a set interval, to a group f…
Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
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.
Suggested Courses

623 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