Help acquiring AD properties

by maindave at 2013-01-11 11:44:49

Hi, I have written a script that output certian AD objects for a AD user account, next i’m retrieving groups AD user is a member of. The problem I’m having is getting the group membership to export as CSV.

function get-userprop {

param (
$user = " "

$userprop=Get-ADUser $user -properties * | sort name
$usermem=(Get-ADUser $user -properties * | select memberof).memberof

$obj = New-Object -typename psobject

$obj | Add-Member -membertype noteproperty <br> -name &quot;First Name&quot; -value ($userprop.givenname)<br> <br> $obj | Add-Member -membertype noteproperty
-name "Last Name" -value ($userprop.surname)

$obj | Add-Member -membertype noteproperty <br> -name &quot;Description&quot; -value ($userprop.description)<br> <br> $obj | Add-Member -membertype noteproperty
-name "Employee ID" -value ($userprop.EmployeeID)

$obj | Add-Member -membertype noteproperty <br> -name &quot;Account Status&quot; -value ($userprop.enabled) <br> <br> $obj | Add-Member -membertype noteproperty
-name "B1 ID" -value ($

$obj | Add-Member -membertype noteproperty <br> -name &quot;OU&quot; -value ($userprop.CanonicalName) <br> <br> $obj | Add-Member -membertype noteproperty
-name "Expiration Date" -value ($userprop.AccountExpirationDate)

$obj | Add-Member -membertype noteproperty `
-name "Group Membership" -value ($usermem)

Write-Output $obj



OUTPUT******** misssing group membership**************
First Name Last Name Description Employee ID Account Status B1 ID OU Expiration Date
XXX xxxxxx xxxxxx xxxxxx xxxxx xxx xx xxxx
by RichardSiddaway at 2013-01-12 01:56:04
Try something like this

$user = "mgreen"

Get-ADUser $user -properties * |
select @{N="FirstName"; E={$.givenname}},
@{N="LastName"; E={$
Description, EmployeeID,
@{N="AccountStatus"; E={$.enabled}},
@{N="B1 ID"; E={$
@{N="OU"; E={$.CanonicalName}},
@{N="Expiration Date"; E={$
@{N="Group Membership"; E={$($_.memberof)}} |
Export-Csv -Path userdata.csv -NoTypeInformation

I'm creating an object using Select-Object. N = Name and E=Expression

Its a simpler way and a lot less typing. I get the group membership as a list in the last field of the CSV
by maindave at 2013-01-15 13:10:29
thx for your asisstance