Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Powershell Groups output to CSV

Posted on 2013-01-29
2
Medium Priority
?
490 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 41

Accepted Solution

by:
footech earned 1500 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

WEBINAR - Latest Cyber Tips for Defense

Join the WatchGuard Threat Research Team on October 26th for an informative webinar featuring expert tips and tricks for defending your organization from today's latest cyber threats. Don't leave yourself vulnerable to attack. Register for the webinar today!

Question has a verified solution.

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

Group policies can be applied selectively to specific devices with the help of groups. Utilising this, it is possible to phase-in group policies, over a period of time, by randomly adding non-members user or computers at a set interval, to a group f…
After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

598 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