Powershell Groups output to CSV

Posted on 2013-01-29
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

Thank you for the assistance!
Question by:patrickm12981
LVL 35

Expert Comment

by:Joseph Daly
Comment Utility
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.
LVL 39

Accepted Solution

footech earned 375 total points
Comment Utility
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)
  $custom | Add-Member -type NoteProperty -name "Group$i" -value $GroupName
$custom | Export-CSV c:\temp\groups.csv -notype

Open in new window


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

Suggested Solutions

Title # Comments Views Activity
Failed 2008r2 6 79
How to transfer FSMO roles 2 38
lync 2013 7 29
Using a variable to name output in powershell script 2 13
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
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 configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

762 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

9 Experts available now in Live!

Get 1:1 Help Now