Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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       'CN=username@domain.edu,OU=domain.edu,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

2 Answers 2

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 admin@live-edu-domain.com-net

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -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.