Solved

Powershell Groups output to CSV

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

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
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 video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

776 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