Azure AD Powershell:提取用户的上次登录时间

2024-03-12

我正在尝试提取用户在 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://learn.microsoft.com/en-us/powershell/module/azuread/get-azureadauditsigninlogs?view=azureadps-2.0-preview https://learn.microsoft.com/en-us/powershell/module/azuread/get-azureadauditsigninlogs?view=azureadps-2.0-preview

你知道我是否需要任何其他模块来运行这个脚本吗?还有其他方法可以获取此信息吗?我需要一个包含所有用户及其上次登录时间的 CSV 文件。

感谢您的帮助。

Cheers,

Gabe

编辑:这是错误消息:

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Azure AD Powershell:提取用户的上次登录时间 的相关文章

随机推荐