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
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
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.
LVL 40

Accepted Solution

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

Open in new window


Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

Windows 10 came with  a lot of built in applications, Some organisations leave them there, some will control them using GPO's. This Article is useful for those who do not want to have any applications in their image (example:me).
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
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…
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 …

726 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