Powershell 脚本未从 Office 365 (MsolService) 获取所需的所有信息

Powershell script not getting all information needed from Office 365 (MsolService)

我正在尝试从我们的 Office 365 获取某些信息,但没有获取所需的所有信息。

下面是我使用的脚本:

Get-MsolUser -All | select DisplayName, LastPasswordChangeTimeStamp, LastLogonTime, PrimaryEmailAddress | Export-CSV UserList.csv -NoTypeInformation

我从上面的脚本中得到的信息只是最后一次密码更改的显示名称。对于 LastLogonTimePrimaryEmailAddress 我一无所获。

我做错了什么吗?

请帮忙。

谢谢

可以从 Get-MailboxStatistics 检索上次登录时间,但它只显示上次访问的 Exchange 邮箱。它不跟踪其他 Office 365 服务。您可以根据您的要求尝试以下代码。

$Result=""  
$Output=@()
Get-mailbox -All | foreach{
$UPN=$_.UserPrincipalName
$DisplayName=$_.DisplayName
$PrimaryEmailAddress=$_.ProxyAddresses.where{$_ -clike "SMTP:*"} -creplace "SMTP:"
$LastPwdChange=$_.LastPasswordChangeTimeStamp
$LastLogonTime=(Get-MailboxStatistics -Identity $upn).lastlogontime
$Result= @{'DisplayNme'=$DisplayName;'LastLogonTime'=$LastLogonTime;'PrimaryEmailAddress'=$PrimaryEmailAddress;'LastPwdChange'=$LastPwdChange}
$Output= New-Object PSObject -Property $Result 
$Output | Select-Object DisplayName,LastLogonTime,PrimaryEmailAddress,LastPwdChange | Export-CSV UserList.csv -Notype -Append
}

脚本来源:Export Office 365 Users last logon time to CSV