powershell - Powershell 脚本未从 Office 365 (MsolService) 获取所需的所有信息
问题描述
我正在尝试从我们的 Office 365 获取某些信息,但没有获得所需的所有信息。
下面是我使用的脚本:
Get-MsolUser -All | select DisplayName, LastPasswordChangeTimeStamp, LastLogonTime, PrimaryEmailAddress | Export-CSV UserList.csv -NoTypeInformation
我从上述脚本中获得的信息只是显示名称最后一次密码更改。对于LastLogonTime
和PrimaryEmailAddress
我一无所获。
有什么我做错了吗?
请帮忙。
谢谢
解决方案
上次登录时间可以从 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
}
推荐阅读
- python - Python,合并具有相同id的行 - 日期但在一列中具有不同的值
- python - 如何在 tkinter 中仅向输入字段添加底部边框?
- python - 在 sigmoid 曲线上找到点
- python - 无法在 python 中使用字符串格式获得所需的输出
- swift - Swift 和 Firebase 中的多个 if let 语句
- python - 为什么 Anaconda/JupyterLab 找不到 guidata?
- php - 如何在选择选项 Ajax get 方法上重新加载页面
- python - 将 1OCT20 转换为日期时间
- oracle - 如何将提取的 ORACLE CLOB 加载到 Postgres 中的仅 1 个 TEXT 列中?
- flutter - Flutter:升级 Flutter 和 Channel 后无法再构建应用程序