Quantcast
Channel: The Official Scripting Guys Forum! forum
Viewing all articles
Browse latest Browse all 15028

get-aduser script with .csv output of Name, UserPrincipalName, Enabled, LastLogonDate, PasswordLastSet, PasswordExpired and non-truncated list of groups memberof

$
0
0


PowerShell Maestros,

My goal using PowerShell v4.0 is to perform a .csv export of all Active Directory domain groups members with specific properties for each domain user account.  I want to create a script to to query Active Directory for all AD user accounts with properties below and all AD security groups each AD user is a member of.

Name, UserPrincipalName, Enabled, LastLogonDate, PasswordLastSet, PasswordExpired  and all AD groups the user is a member of.  Its a challenge indeed!

Any and all scripts, ideas are appreciated.  Thank You!

~ Matt


Attempt #1 starting with Get-Aduser -filter *   (does not display all the AD groups the AD user is a member of)

===============================================================================

get-aduser -filter * -property name, userprincipalname, passwordlastset, passwordexpired, enabled, lastlogondate, memberof | select-object name, userprincipalname, passwordlastset, passwordexpired, enabled, lastlogondate, memberof | Export-CSV -path C:\exportallADgroupwmembers.csv -notypeinformation

I get this output which fails to deliver a non-truncated list of all AD groups the  user is a member of:

===============================================================================

Attempt #2 staring with AD-Group -filter *   (am not able to figure out how to get properties userprincipalname, passwordlastset, passwordexpired, enabled, lastlogondate, memberof to output using this model script)

===============================================================================

$groupmembership=get-adgroup -filter * | 
    ForEach-Object{
        Write-Host $_.Name -fore green
        $props=@{Group=$_.Name;Member=$null}
        $_ | get-adgroupmember |
ForEach-Object{
                    Write-Host "`t$($_.Name)" -fore yellow
                    $props.Member=$_.Name
                    New-Object PsObject -Property $props
                }
}
$groupmembership | export-csv -Path C:\it-dept\exportallADgroupwmembers.csv -notypeinformation

===============================================================================


Matt



Viewing all articles
Browse latest Browse all 15028

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>