Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to get a csv file of all users in a Live@edu environment with a LastLogonTime, but I am having some issues here is my script:

 foreach ($i in (Get-Mailbox -ResultSize unlimited)) 
      { Get-MailboxStatistics -LastLogonTime $i.DistinguishedName | where {$_.LastLogonTime} | select-object MailboxOwnerID,Name,LastLogonTime | export-csv -path "c:\filepath\UserLastLogon.csv" } 

I get the error:

 A positional paparameter cannot be found that accepts argument       ',,OU=Microsoft Exchange Hosted Organizations,DC=prod,DC=exchangelabs,DC=com'.

+Category Info: InvalidArgument: (:) [Get-MailboxStatistics], ParameterBindingException +FullyQualifiedErrorId : PositionalParameterNotFound,Get-MailboxStatistics

Any help would be great!

share|improve this question

You seem to have a problem with your PowerShell syntax in Get-MailboxStatistics call.

Should be

foreach ($i in (Get-Mailbox -ResultSize unlimited)) 
{Get-MailboxStatistics -Identity $i.DistinguishedName | where {$_.LastLogonTime -ne $null} | select-object MailboxOwnerID,Name,LastLogonTime | export-csv -path "c:\filepath\UserLastLogon.csv" } 
share|improve this answer

No CSV, but Eyecandy :-)

$LiveCred = Get-Credential -Credential

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri -Credential $LiveCred -Authentication Basic -AllowRedirection

Import-PSSession $Session


set-alias list       format-list 
set-alias table      format-table 

Get-Mailbox |
  Get-MailboxStatistics |
    Select DisplayName,LastLogonTime,TotalItemSize,ItemCount |
      sort -property lastlogontime |
        ft @{expression={$_.displayname};label=”Postfachbesitzer”}, @{expression={$_.lastlogontime};label=”letzte Anmeldung am”}, @{expression={$_.totalitemsize};label=”Größe”}, @{expression={$_.itemcount};label=”Anzahl Objekte”}>C:\liste.txt

Remove-PSSession $Session
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.