locked
Script to list User, PAsswordLastSet,LastLogonDate, SMTP Address and OU RRS feed

  • Question

  • Dear all,

    Does anybody know a script to list in CSV for columns as below. My AD does not have enough information so the script must combine information in AD and Exhange.

    USer

    PAsswordLastSet

    LAstLogonTime

    SMTPAddress

    OU

    All the users

    Time & Date of password last set(Get in AD?)

    Attributes in Get-mailboxstatistics

    Email Address from Exchange

    OU of each user because different user different OU

    Rgds


    Thursday, March 23, 2017 10:48 AM

Answers

  • Hi

    Per my test you can use the following script:

    $out = @()
    
    
    $users = Get-Mailbox
    
    
    ForEach ($user in $users) {
    
    
        $userMailboxStatistics = Get-MailboxStatistics $user.name
    
        $ADusers = Get-ADuser -identity $user.name -properties * 
    
    
        $props = @{
    
    
            DisplayName = $user.DisplayName
    
            Passwordlastset = $ADusers.PasswordLastSet
    
            OrganizationalUnit = $user.OrganizationalUnit
    
            SmtpAddress = $ADusers.UserPrincipalName
    
            Lastlogontime = $userMailboxStatistics.Lastlogontime
    
           
    
        }
    
    
        $out += New-Object PsObject -Property $props
    
    
    }
    
    
    $out | Sort-Object -Property Passwordlastset | select-object displayname, SmtpAddress, Lastlogontime, OrganizationalUnit, Passwordlastset | Export-Csv c:\ADUserDetails.csv
    

    Test results:

    Hope it helps.


    Regards,

    Jason Chao


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    • Proposed as answer by Jason.ChaoModerator Friday, March 24, 2017 2:57 AM
    • Marked as answer by Bremen6 Tuesday, April 18, 2017 10:30 AM
    Friday, March 24, 2017 2:57 AM
    Moderator

All replies

  • Try this:

    Get-ADUser -Filter * -Properties LastLogonDate,PasswordLastSet,PasswordExpired,MemberOf | Select Name,UserPrincipalName,Enabled,LastLogonDate,PasswordLastSet,PasswordExpired,@{N='Groups';E={ ($_.MemberOf | ForEach { (Get-ADGroup $_).Name } | Sort) -join ',' } } | Export-Csv .\userDetails.csv -NoTypeInformation

    Source:

    https://social.technet.microsoft.com/Forums/en-US/84673e6b-e69b-41e6-9322-f2a6f8d8bc98/getaduser-script-with-csv-output-of-name-userprincipalname-enabled-lastlogondate?forum=ITCG

    https://social.technet.microsoft.com/Forums/en-US/bed43483-616c-4cf0-a26b-becca10e530b/export-a-list-of-all-mailboxes-their-email-addresses-into-a-csv-file?forum=exchangesvradminlegacy

    For just Primary SMTP address then its easy...

    Get-Recipient -ResultSize Unlimited | Select Name, Displayname, PrimarySmtpAddress | export-csv emailaddresses.csv -NoTypeInformation

    And if you want secondary smtp addresses too then you can do via this...

    Get-Recipient -ResultSize Unlimited |Select-Object Name, DisplayName,PrimarySmtpAddress, @{Name=“EmailAddresses”;Expression={$_.EmailAddresses |Where-Object {$_.PrefixString -ceq “smtp”} | ForEach-Object {$_.SmtpAddress}}} | Export-CSV emailaddresses.csv -NoTypeInformation

    After this you would need some type of manipulation in Excel to short by domain etc

    Hope this helps!


    Cloud migration can be a tedious task without the right solution. Lepide Meteor suite has all you need to analyze/upgrade/migrate your current Exchange environment to Office 365 and also helps you to easily Import/Export & convert EDB, PST and OST into new or existing PST files.

    Thursday, March 23, 2017 10:59 AM
  • Hi

    Per my test you can use the following script:

    $out = @()
    
    
    $users = Get-Mailbox
    
    
    ForEach ($user in $users) {
    
    
        $userMailboxStatistics = Get-MailboxStatistics $user.name
    
        $ADusers = Get-ADuser -identity $user.name -properties * 
    
    
        $props = @{
    
    
            DisplayName = $user.DisplayName
    
            Passwordlastset = $ADusers.PasswordLastSet
    
            OrganizationalUnit = $user.OrganizationalUnit
    
            SmtpAddress = $ADusers.UserPrincipalName
    
            Lastlogontime = $userMailboxStatistics.Lastlogontime
    
           
    
        }
    
    
        $out += New-Object PsObject -Property $props
    
    
    }
    
    
    $out | Sort-Object -Property Passwordlastset | select-object displayname, SmtpAddress, Lastlogontime, OrganizationalUnit, Passwordlastset | Export-Csv c:\ADUserDetails.csv
    

    Test results:

    Hope it helps.


    Regards,

    Jason Chao


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    • Proposed as answer by Jason.ChaoModerator Friday, March 24, 2017 2:57 AM
    • Marked as answer by Bremen6 Tuesday, April 18, 2017 10:30 AM
    Friday, March 24, 2017 2:57 AM
    Moderator
  • omg, thank you so much yeayy
    Tuesday, April 18, 2017 10:30 AM