Solved

Get-ADuser output

Posted on 2013-01-28
5
1,424 Views
Last Modified: 2013-01-28
I am using:

(Get-ADUser -Identity jdoe -Properties memberof | Select-Object MemberOf).memberof

to return the group memebership of a selected user, but I get back:

CN=Blah,OU=Blah1,OU=Blah2,DC=Blah3,DC=com

I would like to just get back the group name (CN) instead of the full string.
0
Comment
Question by:patrickm12981
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:coraxal
ID: 38828586
Eliminate the Select-Object
(Get-ADUser -Identity jdoe -Properties memberof).memberof

Open in new window

0
 
LVL 16

Expert Comment

by:Rajitha Chimmani
ID: 38828609
Try the below command which formats the output

(Get-ADUser -Identity jdoe -Properties memberof | Select-Object MemberOf).memberof.split(",")[0].trim("CN=")

Or you could get the output to a variable and use Get-ADgroup command


$group = (Get-ADUser -Identity jdoe -Properties memberof | Select-Object MemberOf).memberof
$group | Get-ADgroup | Select Name

You may have to use a foreach loop if you have multiple groups in the output.

$group = (Get-ADUser -Identity jdoe -Properties memberof | Select-Object MemberOf).memberof
$group | foreach {Get-ADgroup | Select Name}
0
 

Author Comment

by:patrickm12981
ID: 38828672
Eliminating the Select-Object didn't work, I received the same output.

This is the results I received from

(Get-ADUser -Identity jdoe -Properties memberof | Select-Object MemberOf).memberof.split(",")[0].trim("CN=")


Results:
Method invocation failed because [Microsoft.ActiveDirectory.Management.ADProper
tyValueCollection] doesn't contain a method named 'split'.
At line:1 char:92
+ (Get-ADUser -Identity jdoe -Properties memberof | Select-Object MemberOf).
memberof.split <<<< (",")[0].trim("CN=")
    + CategoryInfo          : InvalidOperation: (split:String) [], RuntimeExce
   ption
    + FullyQualifiedErrorId : MethodNotFound
0
 
LVL 16

Accepted Solution

by:
Rajitha Chimmani earned 400 total points
ID: 38828703
Ok...that confirms the output from the command is a collection of values.

Have you tried my third set of commands that i gave you?

$Groups = (Get-ADUser -Identity jdoe -Properties memberof).memberof
$Groups | foreach {$_.split(",")[0].trim("CN=")}
0
 

Author Comment

by:patrickm12981
ID: 38828770
It looks like
$Groups = (Get-ADUser -Identity jdoe -Properties memberof).memberof
$Groups | foreach {$_.split(",")[0].trim("CN=")}

works correctly - Thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
A procedure for exporting installed hotfix details of remote computers using powershell
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now