Having trouble exporting a table of information from Active Directory.

Solved

I'm pretty new to Powershell and I'm trying to gather and export a list of all the user's names, usernames, emails, last logon dates/times, and each security group each user is a member of. I have a one liner of code that has everything except the security group part. I tried looking around and couldn't find anything that I could easily implement into my code since I'm so new at this. Here's what I have so far.

import-module activedirectory

Get-ADUser -Filter * -Properties * | Select-Object -Property Name, SamAccountName, EmailAddress, @{Name="Last logon";Expression={[datetime]::FromFileTime($_.'LastLogon')}} | Sort-Object Name | Format-Table

Posted Sep 1, 2020, 9:35 PM UTC

24
fenrader•

You could use the Get-ADGroup cmdlet and Select the objects you want from each AD Group.

4
Sys_man•

the property memberof contains a list of groups they are a member of.

test with:

get-aduser <user> -properties memberof | select memberof

2
MTossen•

I made a script some time ago that does what you need.

It's not the cleanest or fastest but it gets the job done.

Link

2
PyroKid883OP•

Thanks after tweaking it a bit it worked perfectly.

2