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
Solved

Get-ADuser output

Posted on 2013-01-28
5
1,455 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this article, I am going to show you how to simulate a multi-site Lab environment on a single Hyper-V host. I use this method successfully in my own lab to simulate three fully routed global AD Sites on a Windows 10 Hyper-V host.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

808 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