?
Solved

Get-ADuser output

Posted on 2013-01-28
5
Medium Priority
?
1,551 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 1600 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 Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Had a business requirement to store the mobile number in an environmental variable. This is just a quick article on how this was done.
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 …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

771 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