Welcome to Powergui.org - an open source community for Windows Powershell

PowerGUI.org PowerGUI.org and blogs

Forums » Request a Script

Thread: Need a powershell comand to pull members of security groups in an OU

This question is not answered. Helpful answers available: 2. Answered answers available: 1.


Permlink Replies: 10 - Pages: 1 - Last Post: May 18, 2010 12:52 PM by: Greg Westergren Threads: [ Previous | Next ]
mmoss1107

Posts: 29
Registered: 8/12/09
Need a powershell comand to pull members of security groups in an OU
Posted: Sep 1, 2009 7:20 AM
 
  Click to reply to this thread Reply

Need a powershell comand to pull members of security groups in an OU. Output the results into a CSV file.


hugopeeters


Posts: 22
Registered: 5/27/09
Re: Need a powershell comand to pull members of security groups in an OU
Posted: Sep 1, 2009 8:08 AM   in response to: mmoss1107
 
  Click to reply to this thread Reply

How about something like this:

$myCol = @()
ForEach ($Group in (Get-QADGroup -SearchRoot "OU=FOO,DC=BAR,DC=local" -SizeLimit 0 -GroupType Security))
   {
   ForEach ($Member in (Get-QADGroupMember $Group))
      { 
      $myObj = "" | Select Group, Member
      $myObj.Group = $Group.Name
      $myObj.Member = $Member.Name
      $myCol += $myObj
      }
   }
$myCol | Export-Csv -Path "D:\scripts\file.csv" -NoTypeInformation

Hugo
http://www.peetersonline.nl


mmoss1107

Posts: 29
Registered: 8/12/09
Re: Need a powershell comand to pull members of security groups in an OU
Posted: Sep 1, 2009 11:13 AM   in response to: hugopeeters
 
  Click to reply to this thread Reply

$myCol = @()
  ForEach ($Group in (Get-QADGroup -SearchRoot us.test.com/us firm wide/applications/mail/security groups  -SizeLimit 0 -GroupType Security))
    {
    ForEach ($Member in (Get-QADGroupMember $Group))
        {
        $myObj = "" | Select Group, Member
        $myObj.Group = $Group.Name
        $myObj.Member = $Member.Name
        $myCol += $myObj
        }
    }
  $myCol | Export-Csv -Path "C:\PS\SGMembers.csv" -NoTypeInformation

Here is the error I recieve.

>>
Get-QADGroup : A parameter cannot be found that matches parameter name 'wide/ap
plications/mail/security'.
At line:1 char:35
+   ForEach ($Group in (Get-QADGroup  <<<< -SearchRoot us.test.com/us firm
wide/applications/mail/security groups  -SizeLimit 0 -GroupType Security))



seaJhawk


Posts: 414
Registered: 12/15/08
Re: Need a powershell comand to pull members of security groups in an OU
Posted: Sep 1, 2009 11:38 AM   in response to: mmoss1107
 
  Click to reply to this thread Reply

You just need to quote your -SearchRoot value:

Get-QADGroup -SearchRoot "us.test.com/us firm wide/applications/mail/security groups" ...

-Chris



mmoss1107

Posts: 29
Registered: 8/12/09
Re: Need a powershell comand to pull members of security groups in an OU
Posted: Sep 1, 2009 11:56 AM   in response to: seaJhawk
 
  Click to reply to this thread Reply

Does make since that I get this error when the SizeLimit is set to zero.

WARNING: Only first 1000 search results were displayed. To display more,
increase size limit using -SizeLimit parameter (use 0 as the value of size
limit to display all search results).


seaJhawk


Posts: 414
Registered: 12/15/08
Re: Need a powershell comand to pull members of security groups in an OU
Posted: Sep 1, 2009 11:59 AM   in response to: mmoss1107
 
  Click to reply to this thread Reply

Nope, that doesn't make sense. Sounds like a typo issue.

Can you repost the script that returned that error?

-Chris


mmoss1107

Posts: 29
Registered: 8/12/09
Re: Need a powershell comand to pull members of security groups in an OU
Posted: Sep 1, 2009 12:12 PM   in response to: seaJhawk
 
  Click to reply to this thread Reply

$myCol = @()
  ForEach ($Group in (Get-QADGroup -SearchRoot “us.test.com/us firm wide/applications/mail/security groups”  -SizeLimit 0 -GroupType Security))
    {
    ForEach ($Member in (Get-QADGroupMember $Group))
        {
        $myObj = "" | Select Group, Member
        $myObj.Group = $Group.Name
        $myObj.Member = $Member.Name
        $myCol += $myObj
        }
    }
  $myCol | Export-Csv -Path "C:\SGMembers.csv" -NoTypeInformation



seaJhawk


Posts: 414
Registered: 12/15/08
Re: Need a powershell comand to pull members of security groups in an OU
Posted: Sep 1, 2009 1:56 PM   in response to: mmoss1107
 
  Click to reply to this thread Reply

Out of curiosity, do you have over a thousand security groups in the OU specified?

Everything looks ok to me... Are you running the latest version of the Quest AD cmdlets?

I don't have a single OU with more than a thousand security groups so I can't test with the -searchroot parameter. But if I search at the root of my domain I have over 1000 groups and all of them are returned without the warning.

I am running the latest version of the cmdlets.

-Chris


mmoss1107

Posts: 29
Registered: 8/12/09
Re: Need a powershell comand to pull members of security groups in an OU
Posted: Sep 1, 2009 3:07 PM   in response to: seaJhawk
 
  Click to reply to this thread Reply

889 security groups


seaJhawk


Posts: 414
Registered: 12/15/08
Re: Need a powershell comand to pull members of security groups in an OU
Posted: Sep 2, 2009 1:24 PM   in response to: mmoss1107
 
  Click to reply to this thread Reply

I can't think of any reason you would get the limit warning.

Did you check the version of the AD cmdlets you're running?


Greg Westergren


Posts: 11
Registered: 9/17/09
Re: Need a powershell comand to pull members of security groups in an OU
Posted: May 18, 2010 12:46 PM   in response to: seaJhawk
 
  Click to reply to this thread Reply

Scratch that....it just took a bit longer to pop up.

I ran it with -sizelimit 0 after Get-QADGroup like this and didn't get the error.


$myCol = @()
  ForEach ($Group in (Get-QADGroup -SizeLimit 0 -SearchRoot "" -GroupType Security))
    {
    ForEach ($Member in (Get-QADGroupMember $Group))
        {
        $myObj = "" | Select Group, Member
        $myObj.Group = $Group.Name
        $myObj.Member = $Member.Name
        $myCol += $myObj
        }
    }
Message was edited by: Greg Westergren Message was edited by: Greg Westergren


Legend
MVP: 2501 + pts
Guru: 2001 - 2500 pts
Expert: 751 - 2000 pts
Enthusiast: 31 - 750 pts
Novice: 0 - 30 pts
Moderators
Helpful answer (5 pts)
Answered (10 pts)

Point your RSS reader here for a feed of the latest messages in all forums