Solved

Get-ADuser output

Posted on 2013-01-28
5
1,473 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article explains the steps required to use the default Photos screensaver to display branding/corporate images
Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
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…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

730 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