locked
exchange: list of active users RRS feed

  • Question

  • Hi!

    I got a power Shell script which create a list of our active users.I would like to add ONE more column to it, which tells the Last Success Sync date. Could someone help to accomplish this. Thanks in advance.

    Here's the script to modify:

    $stats = @()
    foreach ($mbx in get-mailbox -resultsize unlimited)
    {
    if ((get-mailboxstatistics $mbx).lastlogontime -gt (get-date).adddays(-30))
    {
    $stat = get-mailboxstatistics $mbx | select displayname,lastlogontime
    $stat | add-member -membertype noteproperty -name "Quota (MB)" -value "$($mbx.ProhibitSendQuota.Value.ToMB())"
    $stat | add-member -membertype noteproperty -name "UPN" -value "$($mbx.UserPrincipalName)"
    $stat | add-member -membertype noteproperty -name "OU" -value "$($mbx.OrganizationalUnit)"
    $stats += $stat
    }
    }
    $stats | sort-object -property OU | ft -autosize | out-file c:\ActiveUsers.txt -width 640
    Thursday, September 1, 2011 12:08 PM

Answers

  • Hi Fabi,

     

    As Simon said, you might be better asking this on the forum he mentioned.

    However, here is a possible solution to your question:

    $mbcombCollection = @()
    
    ForEach ($mbx in Get-Mailbox -ResultSize Unlimited)
    {
    	$mbStats = Get-MailboxStatistics $mbx | Select DisplayName, LastLogonTime, ProhibitSendQuota
    
    	If ($mbStats.LastLogonTime -gt (Get-Date).AddDays(-30))
    	{
    		$mbcomb = "" | Select "Display Name", "Last Logon Time", "Quota (MB)", "UPN", "OU", "Last Suc Sync"
    
    		$mbcomb."Display Name" = $mbStats.DisplayName
    		$mbcomb."Last Logon Time" = $mbStats.LastLogonTime
    		$mbcomb."Quota (MB)" = $mbx.ProhibitSendQuota
    		$mbcomb."UPN" = $mbx.UserPrincipalName
    		$mbcomb."OU" = $mbx.OrganizationalUnit
    		$mbcomb."Last Suc Sync" = (Get-ActiveSyncDeviceStatistics -Mailbox $mbx).LastSuccessSync
    
    		$mbcombCollection += $mbcomb
    	}
    }
    
    $mbcombCollection | Export-Csv D:\Reports\"ActiveUsers_$(Get-Date -f 'yyyyMMdd').csv" -NoType
    


    Hope this helps!


    http://LetsExchange.blogspot.com
    • Proposed as answer by Nuno Mota Thursday, September 8, 2011 12:52 PM
    • Marked as answer by fabi.balazs Thursday, September 8, 2011 1:15 PM
    Tuesday, September 6, 2011 10:15 AM

All replies

  • Hello,

    For the script related questions, please create a new thread to the following forum which will be more appropriate:

     

    http://social.technet.microsoft.com/Forums/en-US/exchangesvrdevelopment/threads


    Thanks,
    Simon

    Monday, September 5, 2011 3:02 AM
    Moderator
  • Hi Fabi,

     

    As Simon said, you might be better asking this on the forum he mentioned.

    However, here is a possible solution to your question:

    $mbcombCollection = @()
    
    ForEach ($mbx in Get-Mailbox -ResultSize Unlimited)
    {
    	$mbStats = Get-MailboxStatistics $mbx | Select DisplayName, LastLogonTime, ProhibitSendQuota
    
    	If ($mbStats.LastLogonTime -gt (Get-Date).AddDays(-30))
    	{
    		$mbcomb = "" | Select "Display Name", "Last Logon Time", "Quota (MB)", "UPN", "OU", "Last Suc Sync"
    
    		$mbcomb."Display Name" = $mbStats.DisplayName
    		$mbcomb."Last Logon Time" = $mbStats.LastLogonTime
    		$mbcomb."Quota (MB)" = $mbx.ProhibitSendQuota
    		$mbcomb."UPN" = $mbx.UserPrincipalName
    		$mbcomb."OU" = $mbx.OrganizationalUnit
    		$mbcomb."Last Suc Sync" = (Get-ActiveSyncDeviceStatistics -Mailbox $mbx).LastSuccessSync
    
    		$mbcombCollection += $mbcomb
    	}
    }
    
    $mbcombCollection | Export-Csv D:\Reports\"ActiveUsers_$(Get-Date -f 'yyyyMMdd').csv" -NoType
    


    Hope this helps!


    http://LetsExchange.blogspot.com
    • Proposed as answer by Nuno Mota Thursday, September 8, 2011 12:52 PM
    • Marked as answer by fabi.balazs Thursday, September 8, 2011 1:15 PM
    Tuesday, September 6, 2011 10:15 AM
  • That's great! Thank You!
    Thursday, September 8, 2011 2:12 PM