 |
|
|
Issue executing GroupMembership script
Last Post 03 Oct 2011 08:54 AM by googleface. 5 Replies.
|
Sort:
|
|
Prev Next |
You are not authorized to post a reply. |
|
the_tweaker
 New Member Posts:8

 |
| 14 May 2009 06:18 AM |
|
Hello Shay,
Thanks for the Update Shay. However, now I have a new error: "Get-QADGroup : Cannot validate argument on parameter 'Identity'. The argument cannot be null or empty. At C:\Program Files\Quest Software\Management Shell for AD\User_CSV_GroupMembership.ps1:5 char:117 + "{0}, {1}, {2}, {3}" -f $_.samaccountname, $_.firstname, $_.lastname, [string]::join(",",($_.memberOf | Get-QADGroup <<<< | foreach {$_.name})) + CategoryInfo : InvalidData: (:) [Get-QADGroup], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Quest.ActiveRoles.ArsPowerShellSnapIn.Cmdlets.GetGroupCmdlet2 Exception calling "Join" with "2" argument(s): "Value cannot be null. Parameter name: value" At C:\Program Files\Quest Software\Management Shell for AD\User_CSV_GroupMembership.ps1:5 char:85 + "{0}, {1}, {2}, {3}" -f $_.samaccountname, $_.firstname, $_.lastname, [string]::join <<<< (",",($_.memberOf | Get-QADGroup | foreach {$_.name})) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException. I am calling the script from within the Windows Powershell Integrated Scripting Environment.
I was able to get a little further with another script which does provide results: Import-Csv users.csv | Get-QADUser -Identity {$_.user} | foreach { "{0}, {1}" -f $_.samaccountname, [string]::join(",",($_.memberOf | Get-QADGroup | foreach {$_.name})) }
However when I try to print the results to a csv using Import-Csv users.csv | Get-QADUser -Identity {$_.user} | foreach { "{0}, {1}" -f $_.samaccountname, [string]::join(",",($_.memberOf | Get-QADGroup | foreach {$_.name})) } | export-csv d:\grouptest.csv,
then I get the following error: Get-QADGroup : Cannot validate argument on parameter 'Identity'. The argument cannot be null or empty. At C:\Program Files\Quest Software\Management Shell for AD\1User_GroupMembership.ps1:2 char:80 + "{0}, {1}" -f $_.samaccountname, [string]::join(",",($_.memberOf | Get-QADGroup <<<< | foreach {$_.name})) + CategoryInfo : InvalidData: (:) [Get-QADGroup], ParameterBindingValidationException + FullyQualifiedErrorId : ParameterArgumentValidationError,Quest.ActiveRoles.ArsPowerShellSnapIn.Cmdlets.GetGroupCmdlet2 Exception calling "Join" with "2" argument(s): "Value cannot be null. Parameter name: value" At C:\Program Files\Quest Software\Management Shell for AD\1User_GroupMembership.ps1:2 char:48 + "{0}, {1}" -f $_.samaccountname, [string]::join <<<< (",",($_.memberOf | Get-QADGroup | foreach {$_.name})) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
Any help would be greatly appreciated. |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 14 May 2009 08:34 AM |
|
Try with this: $groups = @{n="groups";e={ [string]::join(",",($_.memberOf | Get-QADGroup | foreach {$_.name})) }} Import-Csv D:\Scripts\temp\users.csv | Get-QADUser -Identity {$_.user} | select samaccountname,$groups | export-csv d:\grouptest.csv
|
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
the_tweaker
 New Member Posts:8

 |
| 15 May 2009 01:41 AM |
|
Hello Shay,
Thanks, that works better, but now I have a new problem. I keep running into a memory overflow. The script runs and creates the csv with what appears to be correct information, but after running about 10 minutes, local memory usages is up to 1.4gb and then the powershell ise closes. Additionally, it seems to be taking a very long time. I am trying to get the group membership of about 13,000 users. I have a script in VB that does it in about 4 minutes but for some reason, the results do not match does of the MMC. I am basically doing the same, scanning the AD root for User samaccount and memberOf. But, the VBscript returns more groups than actually are assigned. As I would like to make the transition to Powershell, any assistance you can give me would be greatly appreciated. |
|
|
|
|
Shay Levy PowerShell MVP, Admin
 Veteran Member Posts:1362

 |
| 15 May 2009 04:10 AM |
|
Try this version, it should run faster. Group names are extracted with a regular expression instead of a Get-QADGroup for each group membership: $groups = @{n="groups";e={ [string]::join(";",($_.memberof | foreach { [regex]::match($_,'(?<=CN=)([^,]+)').value }))}} Import-Csv D:\Scripts\temp\users.csv | Get-QADUser -Identity {$_.user} | select samaccountname,$groups | export-csv d:\grouptest.csv
|
|
Shay Levy Windows PowerShell MVP
http://PowerShay.com
PowerShell Community Toolbar
Twitter: @ShayLevy |
|
|
the_tweaker
 New Member Posts:8

 |
| 20 May 2009 03:49 AM |
|
Thanks Shay, That works better, Now to extend functionality! I will play a little. |
|
|
|
|
googleface
 New Member Posts:7

 |
| 03 Oct 2011 08:54 AM |
|
Hi Shay, How do I get the groups to display in a tabular format from top to bottom, I guess I have to change regex to have a carriag return in it somehow? How can I also dump out the nested group memberships as well, I assume I use $_.nestedmemberof but how do I incorporate this into the script please? Cheers GF |
|
|
|
|
| You are not authorized to post a reply. |
|
Active Forums 4.3
|
|
 |