total members and inactive members belong to Security Groups

Welcome Forums General PowerShell Q&A total members and inactive members belong to Security Groups

Viewing 0 reply threads
  • Author
    Posts
    • #6217
      Participant
      Topics: 1562
      Replies: 0
      Points: 1
      Rank: Member

      by taheito at 2012-11-19 02:00:29

      We have a parent OU called Schools that contains OU for each School, and each School OU contains a security group called ”SchoolName Teachers" that contains every School teachers when running the script to get each groups Total members and -NotLoggedOnFor X days it gives me the total number for all teachers and total -NotLoggedOnFor for all teachers not for each school separately .

      this is the used script

      ( Get-QADGroup -Name "* Teachers" -SearchRoot "OU=Schools,DC=secedu,DC=qa" -SizeLimit 0 | Foreach{
      $u=Get-QADGroup -Name "* Teachers" -SearchRoot "OU=Schools,DC=secedu,DC=qa" -SizeLimit 0 | Get-QADGroupMember
      $f=Get-QADGroup -Name "* Teachers" -SearchRoot "OU=Schools,DC=secedu,DC=qa" -SizeLimit 0 | Get-QADGroupMember |get-qaduser -NotLoggedOnFor 47 -SizeLimit 0 -PageSize 2000
      $FilePath = $FilePath = "c:\1\Teachers200.csv"
      $total=($u | measure-object).count
      $disabled=($u | where {$_.AccountIsDisabled} | Measure-Object).count
      $NotLoggedOnFor=($f | measure-object).count
      $Enabled=$total-$disabled
      $ActiveUsers=$Enabled-$NotLoggedOnFor
      New-Object psobject -Property @{
      Name=$_.Name;
      Group=$_.DN;
      Description=$_.Description;
      TotalUsers=$Total;
      Enabled=$Enabled;
      Disabled=$Disabled
      ActiveUsers=$ActiveUsers}
      })

      by kittH at 2012-11-19 06:29:30

      Your initial query gets all of the groups named "* Teachers" in the Schools OU. You then run a foreach loop for each of those groups.

      The first two items in the loop run the same query that generated the group list. Inside each loop you’re getting all of the users in all of the groups.

      Try changing the lines to:
      $u = $_ | Get-QADGroupMember
      $f = $_ | Get-QADGroupMember | get-qaduser -NotLoggedOnFor 47 -SizeLimit 0 -PageSize 2000

      by ArtB0514 at 2012-11-19 08:49:07

      There’s no need to use -SizeLimit or -PageSize on this Get-QADuser unless there are more than 1,000 teachers in a group.

      by taheito at 2012-11-19 13:32:55

      Your initial query gets all of the groups named "* Teachers" in the Schools OU. You then run a foreach loop for each of those groups.

      The first two items in the loop run the same query that generated the group list. Inside each loop you’re getting all of the users in all of the groups.

      Try changing the lines to:
      $u = $_ | Get-QADGroupMember
      $f = $_ | Get-QADGroupMember | get-qaduser -NotLoggedOnFor 47 -SizeLimit 0 -PageSize 2000

      Hello kittH,
      thanx allot for your help it’s working now well 🙂

      by taheito at 2012-11-19 13:35:02

      There’s no need to use -SizeLimit or -PageSize on this Get-QADuser unless there are more than 1,000 teachers in a group.

      Hello ArtB0514
      there are some groups that has more 1000 user

Viewing 0 reply threads
  • The topic ‘total members and inactive members belong to Security Groups’ is closed to new replies.