azure - Azure AD Powershell:提取用户的上次登录时间
问题描述
我试图在我们的 Active Directory 上提取用户的上次登录时间,我发现了这个脚本,它应该可以解决问题:
Install-Module AzureADPreview
Import-Module AzureADPreview
$Cred = Get-Credential
Connect-MsolService -Credential $Cred
Connect-AzureAD -Credential $Cred
$Users = Get-MsolUser -all
$Headers = "DisplayName`tUserPrincipalName`tLicense`tLastLogon" >>C:\list.csv
ForEach ($User in $Users)
{
$UPN = $User.UserPrincipalName
$LoginTime = Get-AzureAdAuditSigninLogs -top 1 -filter "userprincipalname eq '$UPN'" | select CreatedDateTime
$NewLine = $User.DisplayName + "`t" + $User.UserPrincipalName + "`t" + $User.Licenses.AccountSkuId + "`t" + $LoginTime.CreatedDateTime
$NewLine >>'C:\list.csv'
}
但由于某种原因,Powershell 似乎无法识别“Get-AzureAdAuditSigninLogs”输入,即使根据 technet 的正确模块是我在脚本开头安装的“AzureADPreview”: https ://docs.microsoft .com/en-us/powershell/module/azuread/get-azureadauditsigninlogs?view=azureadps-2.0-preview
你知道我是否需要任何其他模块来运行这个脚本?是否有其他方法可以获取此信息?我需要一个包含所有用户及其最后登录时间的 CSV 文件。
谢谢您的帮助。
干杯,
加布
编辑:这是错误消息:
Get-AzureAdAuditSigninLogs : The term 'Get-AzureAdAuditSigninLogs' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or
if a path was included, verify that the path is correct and try again.
At line:12 char:18
+ $LoginTime = Get-AzureAdAuditSigninLogs -top 1 -filter "userprinc ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (Get-AzureAdAuditSigninLogs:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
解决方案
这对我有帮助
Install-Module AzureADPreview -AllowClobber -Force
推荐阅读
- python-2.7 - 当我们从 Airflow 网络服务器触发 DAG 时,气流调度程序崩溃
- python - 具有合理默认值的必填字段
- npm - Azure 工件私有 npm 源身份验证失败
- python - 如何在 PyQt5 中的 Ui 和 Classes 之间交换数据?
- http - JVM 应用程序可以建立的最大传出 HTTP 连接数是多少?
- javascript - Javascript 颜色按钮
- angular - 使用 bazel 在角度应用程序中指定基本 href
- php - 使用 Supervisor 持续运行 laravel-echo-server
- html - Firefox 不在 Azure 网站上显示输入
- tensorflow - 如何使用 TensorFlow Serving 打开 JPG 图像并调整其大小?