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

我正在尝试使用LastLogonTime在Live @ edu环境中获取所有用户的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

任何帮助将是伟大的!

您在Get-MailboxStatistics调用中似乎遇到PowerShell语法的问题。

应该

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

没有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