使用 powershell 获取 Live@edu 上的用户 LastLogonTime

使用 powershell 获取 Live@edu 上的用户 LastLogonTime

我正在尝试获取 Live@edu 环境中所有用户的具有 LastLogonTime 的 csv 文件,但我的脚本出现了一些问题:

 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" } 

我收到错误:

 A positional paparameter cannot be found that accepts argument       '[email protected],OU=domain.edu,OU=Microsoft Exchange Hosted Organizations,DC=prod,DC=exchangelabs,DC=com'.

+类别信息:InvalidArgument:(:) [Get-MailboxStatistics],ParameterBindingException +FullyQualifiedErrorId:PositionalParameterNotFound,Get-MailboxStatistics

任何帮助都将非常有帮助!

答案1

您的 PowerShell 调用语法似乎有问题Get-MailboxStatistics

应该

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" } 

答案2

没有 CSV,但是 Eyecandy :-)

$LiveCred = Get-Credential -Credential [email protected]

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $LiveCred -Authentication Basic -AllowRedirection

Import-PSSession $Session

cls

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

相关内容