gpt4 book ai didi

Azure AD Powershell : Extract the User's last Logon Time

转载 作者:行者123 更新时间:2023-12-04 17:24:56 26 4
gpt4 key购买 nike

我正在尝试提取用户在 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

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

最佳答案

这对我有帮助安装模块 AzureADPreview -AllowClobber -Force

关于Azure AD Powershell : Extract the User's last Logon Time,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64062419/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com