Solved

Powershell Groups output to CSV

Posted on 2013-01-29
2
483 Views
Last Modified: 2013-01-29
I'm trying to output these commands:

$Groups1 = (Get-ADUser -Identity $name -Properties memberof).memberof
$Groups = $Groups1 | foreach {$_.split(",")[0].Substring(3)}

to a CSV file. I would like the output to be in the following format:

$username, group1,group2,group3

I tried:
$Groups | Export-Csv C:\DisableTest.csv

but I get:

#TYPE System.String
Length
29
7
7
12
13
12
14
20
11
13

Thank you for the assistance!
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 Comments
 
LVL 35

Expert Comment

by:Joseph Daly
ID: 38832056
I dont have 2008 r2 domain controllers so I cant do it with the AD cmdlets. Would you have any issue with using the quest cmdlets.

figured id ask before I started.
0
 
LVL 40

Accepted Solution

by:
footech earned 375 total points
ID: 38832178
I find myself wondering how useful this will be, and how it might need to modified if part of a larger script, but this should do what you asked (worked for me in testing).
Import-Module ActiveDirectory
$name = "jdoe"
$Groups1 = (Get-ADUser -Identity $name -Properties memberof).memberof
$Groups = $Groups1 | foreach {$_.split(",")[0].Substring(3)}

$i = 0
$custom = New-Object PSObject
$custom | Add-Member -type NoteProperty -name "Name" -value $name
ForEach ($GroupName in $Groups)
{
  $i++
  $custom | Add-Member -type NoteProperty -name "Group$i" -value $GroupName
}
$custom | Export-CSV c:\temp\groups.csv -notype

Open in new window

0

Featured Post

Free NetCrunch network monitor licenses!

Only on Experts-Exchange: Sign-up for a free-trial and we'll send you your permanent license!

Here is what you get: 30 Nodes | Unlimited Sensors | No Time Restrictions | Absolutely FREE!

Act now. This offer ends July 14, 2017.

Question has a verified solution.

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

This article demonstrates probably the easiest way to configure domain-wide tier isolation within Active Directory. If you do not know tier isolation read https://technet.microsoft.com/en-us/windows-server-docs/security/securing-privileged-access/s…
My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…

690 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