Solved

Get-ADuser output

Posted on 2013-01-28
5
1,403 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
Comment Utility
Eliminate the Select-Object
(Get-ADUser -Identity jdoe -Properties memberof).memberof

Open in new window

0
 
LVL 16

Expert Comment

by:Rajitha Chimmani
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
It looks like
$Groups = (Get-ADUser -Identity jdoe -Properties memberof).memberof
$Groups | foreach {$_.split(",")[0].trim("CN=")}

works correctly - Thank you
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

"Migrate" an SMTP relay receive connector to a new server using info from an old server.
Synchronize a new Active Directory domain with an existing Office 365 tenant
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 tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles to another domain controller. Log onto the new domain controller with a user account t…

743 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

17 Experts available now in Live!

Get 1:1 Help Now