bsharath
asked on
Query a OU and all Ou's below it and get each users membership and count alone.
Hi,
Query a OU and all Ou's below it and get each users membership and count alone.
Like
Username 10
Groupname
Groupname2
The same for all users into a csv.
Regards
sharath
Vbs or powershell
Regards
sharath
Query a OU and all Ou's below it and get each users membership and count alone.
Like
Username 10
Groupname
Groupname2
The same for all users into a csv.
Regards
sharath
Vbs or powershell
Regards
sharath
ASKER
yes i want the count of membership of each user
Ad 2003 and 2008
Ad 2003 and 2008
In theory this should work. The formatting is a bit basic, but we can't output directly to CSV since there's no real format.
Anyway, give it a shot? Quest CmdLets again.
Chris
$OutputFile = "somefile.txt"
Get-QADUser -SearchRoot "ou=somewhere,dc=domain,dc=com" -SizeLimit 0 | ForEach-Object {
"$($_.SamAccountName) $($_.MemberOf.Count)"
Get-QADGroup -ContainsMember $_.DN | ForEach-Object { " $_.Name" }
""
} > $OutputFile
ASKER
Thanks works fine
I get .Name next to each group. Can this be removed and can i get in any other format where i can later filter the counts alone
Or have the data sorted from smallest to large while outputting itself
I get .Name next to each group. Can this be removed and can i get in any other format where i can later filter the counts alone
Or have the data sorted from smallest to large while outputting itself
Sorry, fixed here :)
Other formats... You can't really sort at all in the current format. The username, count and groups would all need to be a single data set, and in CSV that means a single line.
How would you like it to be formatted?
Chris
$OutputFile = "somefile.txt"
Get-QADUser -SearchRoot "ou=somewhere,dc=domain,dc=com" -SizeLimit 0 | ForEach-Object {
"$($_.SamAccountName) $($_.MemberOf.Count)"
Get-QADGroup -ContainsMember $_.DN | ForEach-Object { " $($_.Name)" }
""
} > $OutputFile
ASKER
ASKER
After a long run and a lot of output i got this
Get-QADGroup : An invalid directory pathname was passed
At line:3 char:15
+ Get-QADGroup <<<< -ContainsMember $_.DN | ForEach-Object { " $($_.Name)" }
+ CategoryInfo : NotSpecified: (:) [Get-QADGroup], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServ ices.COMEx ception,Qu est.Active Roles.ArsP owerShellS napIn.Powe rs
hell.Cmdlets.GetGroupCmdle t
Get-QADGroup : An invalid directory pathname was passed
At line:3 char:15
+ Get-QADGroup <<<< -ContainsMember $_.DN | ForEach-Object { " $($_.Name)" }
+ CategoryInfo : NotSpecified: (:) [Get-QADGroup], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServ
hell.Cmdlets.GetGroupCmdle
Sample.xls doesn't really mean anything to me, is it the right file?
That suggests one the users contains a reserved character in their distinguished name.
Lets try this version, see if we can skip around that.
Chris
$OutputFile = "somefile.txt"
Get-QADUser -SearchRoot "ou=somewhere,dc=domain,dc=com" -SizeLimit 0 | ForEach-Object {
"$($_.SamAccountName) $($_.MemberOf.Count)"
Get-QADGroup -ContainsMember $_.SamAccountName | ForEach-Object { " $($_.Name)" }
""
} > $OutputFile
ASKER
I posted the xls to give an idea on the format the csv is needed so can filter the counts..
:-)
:-)
ASKER
Hi Chris any views....
Sorry, busy days.
So, the format. Do you only want the group count? Not sure how the list of groups fits into the sample.
Chris
ASKER
I want the count and group membership as well.
The only logic would be to be able to filter the count...
The only logic would be to be able to filter the count...
Which goes back to formatting :)
I can't say I know Excel particularly well, but if we have this format:
SomeName,GroupCount
,Group1
,Group2
Then you will not be able to sort on count.
Chris
ASKER
Can i get as this
SomeName, GroupCount
2 Group1
Group2
SomeName,
3 Group1
Group2
Group3
SomeName, GroupCount
2 Group1
Group2
SomeName,
3 Group1
Group2
Group3
ASKER
Hi Chris any views...
Any help with these
https://www.experts-exchange.com/questions/26286691/Remove-all-nested-groups-within-a-group-and-add-members-that-are-in-that-group-to-the-base-group.html
https://www.experts-exchange.com/questions/26280094/Powershell-script-that-can-query-a-OU-and-get-all-group-name-Members-and-count-of-members-into-a-csv-Excel.html
https://www.experts-exchange.com/questions/26247250/Powershell-script-to-check-no-of-members-in-each-group-and-log-the-data-with-count-and-get-the-groups-that-has-identical-no-of-users-and-names.html
Any help with these
https://www.experts-exchange.com/questions/26286691/Remove-all-nested-groups-within-a-group-and-add-members-that-are-in-that-group-to-the-base-group.html
https://www.experts-exchange.com/questions/26280094/Powershell-script-that-can-query-a-OU-and-get-all-group-name-Members-and-count-of-members-into-a-csv-Excel.html
https://www.experts-exchange.com/questions/26247250/Powershell-script-to-check-no-of-members-in-each-group-and-log-the-data-with-count-and-get-the-groups-that-has-identical-no-of-users-and-names.html
ASKER
A reminder Chris...
Like this?
Kind of tricky to put the group count on the same line as the groups, unless the groups are packed into a single cell.
Chris
$OutputFile = "somefile.txt"
"Username,GroupCount,Groups" > $OutputFile
Get-QADUser -SearchRoot "ou=somewhere,dc=domain,dc=com" -SizeLimit 0 | ForEach-Object {
"$($_.SamAccountName),$($_.MemberOf.Count)"
Get-QADGroup -ContainsMember $_.SamAccountName | ForEach-Object { ",,$($_.Name)" }
} > $OutputFile
ASKER
I get the format perfecta nd get a lot of data also.
But at the end of script completion i get this
Get-QADGroup : An invalid directory pathname was passed
At line:3 char:15
+ Get-QADGroup <<<< -ContainsMember $_.SamAccountName | ForEach-Object { ",,$($_.Name)" }
+ CategoryInfo : NotSpecified: (:) [Get-QADGroup], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServ ices.COMEx ception,Qu est.Active Roles.ArsP owerShellS napIn.Powe rs
hell.Cmdlets.GetGroupCmdle t
Get-QADUser : LDAP://I04.lth.local/schem a/departme nt
At line:1 char:12
+ Get-QADUser <<<< -SearchRoot "OU=users,OU=C,OU=ia,OU=Oc es,DC=lth, DC=local" -SizeLimit 0 | ForEach-
Object {
+ CategoryInfo : NotSpecified: (:) [Get-QADUser], InvalidPathnameException
+ FullyQualifiedErrorId : Quest.ActiveRoles.ArsPower ShellSnapI n.Director yAccess.In validPathn ameExcepti on,Quest.A ct
iveRoles.ArsPowerShellSnap In.Powersh ell.Cmdlet s.GetUserC mdlet
But at the end of script completion i get this
Get-QADGroup : An invalid directory pathname was passed
At line:3 char:15
+ Get-QADGroup <<<< -ContainsMember $_.SamAccountName | ForEach-Object { ",,$($_.Name)" }
+ CategoryInfo : NotSpecified: (:) [Get-QADGroup], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServ
hell.Cmdlets.GetGroupCmdle
Get-QADUser : LDAP://I04.lth.local/schem
At line:1 char:12
+ Get-QADUser <<<< -SearchRoot "OU=users,OU=C,OU=ia,OU=Oc
Object {
+ CategoryInfo : NotSpecified: (:) [Get-QADUser], InvalidPathnameException
+ FullyQualifiedErrorId : Quest.ActiveRoles.ArsPower
iveRoles.ArsPowerShellSnap
Hmm try this?
Chris
$OutputFile = "somefile.txt"
"Username,GroupCount,Groups" > $OutputFile
Get-QADUser -SearchRoot "ou=somewhere,dc=domain,dc=com" -SizeLimit 0 | ForEach-Object {
"$($_.SamAccountName),$($_.MemberOf.Count)"
Get-QADGroup -ContainsMember $_.DN | ForEach-Object { ",,$($_.Name)" }
} > $OutputFile
ASKER
I still get the same error in the initial stage itself...
It doesn't output anything?
You'll need to check the value for SearchRoot if it doesn't.
Chris
ASKER
I get this
Get-QADUser : Server not exist or could not be contacted: DC04.lth.local
At line:1 char:12
+ Get-QADUser <<<< -SearchRoot "OU=users,OU=Ch,OU=Iia,OU= Offices,DC =th,DC=loc al" -SizeLimit 0 | ForEach-
Object {
+ CategoryInfo : NotSpecified: (:) [Get-QADUser], ServerNotOperationalExcept ion
+ FullyQualifiedErrorId : Quest.ActiveRoles.ArsPower ShellSnapI n.Director yAccess.Se rverNotOpe rationalEx ception,Qu es
t.ActiveRoles.ArsPowerShel lSnapIn.Po wershell.C mdlets.Get UserCmdlet
Get-QADUser : Server not exist or could not be contacted: DC04.lth.local
At line:1 char:12
+ Get-QADUser <<<< -SearchRoot "OU=users,OU=Ch,OU=Iia,OU=
Object {
+ CategoryInfo : NotSpecified: (:) [Get-QADUser], ServerNotOperationalExcept
+ FullyQualifiedErrorId : Quest.ActiveRoles.ArsPower
t.ActiveRoles.ArsPowerShel
You can connect to a specific server with:
$OutputFile = "somefile.txt"
"Username,GroupCount,Group
Get-QADUser -SearchRoot "ou=somewhere,dc=domain,dc
"$($_.SamAccountName),$($_
Get-QADGroup -ContainsMember $_.DN -Service "yourserver" | ForEach-Object { ",,$($_.Name)" }
} > $OutputFile
Note that you must set the Service parameter twice, once for Get-QADUser, and once for get-QADGroup.
Might be a good idea to find out why it can't talk to dc04 though.
Chris
ASKER
I get this
Get-Mailbox : Missing an argument for parameter 'RecipientTypeDetails'. Specify
a parameter of type 'Microsoft.Exchange.Data.D irectory.R ecipient.R ecipientTy pe
Details[]' and try again.
At line:1 char:126
+ Get-Mailbox -OrganizationalUnit "OU=Ch,OU=Ia,OU=Oes,DC=lth ,DC=local" -ResultSize 8000 -RecipientTypeDetails <<<< | %{
+ CategoryInfo : InvalidArgument: (:) [Get-Mailbox], ParameterBin
dingException
+ FullyQualifiedErrorId : MissingArgument,Microsoft. Exchange.M anagement. Re
cipientTasks.GetMailbox
Get-Mailbox : Missing an argument for parameter 'RecipientTypeDetails'. Specify
a parameter of type 'Microsoft.Exchange.Data.D
Details[]' and try again.
At line:1 char:126
+ Get-Mailbox -OrganizationalUnit "OU=Ch,OU=Ia,OU=Oes,DC=lth
+ CategoryInfo : InvalidArgument: (:) [Get-Mailbox], ParameterBin
dingException
+ FullyQualifiedErrorId : MissingArgument,Microsoft.
cipientTasks.GetMailbox
Wrong thread? Because it's not a command I've used here.
Chris
ASKER
Sorry :-(
Get-QADGroup : An invalid directory pathname was passed
At line:3 char:15
+ Get-QADGroup <<<< -ContainsMember $_.DN -Service "dc01" | ForEach-Object { ",,$($_.Name)" }
+ CategoryInfo : NotSpecified: (:) [Get-QADGroup], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServ ices.COMEx ception,Qu est.Active Roles.ArsP owerShellS napIn.Powe rs
hell.Cmdlets.GetGroupCmdle t
Get-QADUser : LDAP://DC01.lth.local/sche ma/departm ent
At line:1 char:12
+ Get-QADUser <<<< -SearchRoot "OU=Chi,OU=Iio,OU=Offices, DC=lth,DC= local" -SizeLimit 0 -Service "dc01" | ForEach-Object {
+ CategoryInfo : NotSpecified: (:) [Get-QADUser], InvalidPathnameException
+ FullyQualifiedErrorId : Quest.ActiveRoles.ArsPower ShellSnapI n.Director yAccess.In validPathn ameExcepti on,Quest.A ct
iveRoles.ArsPowerShellSnap In.Powersh ell.Cmdlet s.GetUserC mdlet
Get-QADGroup : An invalid directory pathname was passed
At line:3 char:15
+ Get-QADGroup <<<< -ContainsMember $_.DN -Service "dc01" | ForEach-Object { ",,$($_.Name)" }
+ CategoryInfo : NotSpecified: (:) [Get-QADGroup], COMException
+ FullyQualifiedErrorId : System.Runtime.InteropServ
hell.Cmdlets.GetGroupCmdle
Get-QADUser : LDAP://DC01.lth.local/sche
At line:1 char:12
+ Get-QADUser <<<< -SearchRoot "OU=Chi,OU=Iio,OU=Offices,
+ CategoryInfo : NotSpecified: (:) [Get-QADUser], InvalidPathnameException
+ FullyQualifiedErrorId : Quest.ActiveRoles.ArsPower
iveRoles.ArsPowerShellSnap
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I get this
Get-QADUser : Server not exists or could not be contacted.
At line:1 char:12
+ Get-QADUser <<<< -SearchRoot "OU=C,OU=I,OU=O,DC=lth,DC= local" -SizeLimit 0 -Service "dc01" | ForEach-Object {
+ CategoryInfo : NotSpecified: (:) [Get-QADUser], Exception
+ FullyQualifiedErrorId : System.Exception,Quest.Act iveRoles.A rsPowerShe llSnapIn.P owershell. Cmdlets.Ge tUserCmdle t
Get-QADUser : Server not exists or could not be contacted.
At line:1 char:12
+ Get-QADUser <<<< -SearchRoot "OU=C,OU=I,OU=O,DC=lth,DC=
+ CategoryInfo : NotSpecified: (:) [Get-QADUser], Exception
+ FullyQualifiedErrorId : System.Exception,Quest.Act
It doesn't like the server name you've specified... I can't do a lot to help with that one unless I was onsite doing it for you :)
Chris
Do you need the recursive memberships of the users?