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

标签 azure 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://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/

相关文章:

powershell - 在 PowerShell 作业中使用本地函数

variables - Powershell-使用通配符搜索文件名

powershell - 在保留 Set-Location 开关的同时扩展 cd 功能

regex - 优化 PowerShell 中的 RegEx 匹配

android - 测试 MobileServiceSQLiteStore 时无法加载文件或程序集 `SQLitePCL`

Azure 数据工厂 - 将数据从本地 SQL 移动到 Azure SQL

Azure 相关错误 - VS 2013 Professional - 'CctProjectPackage' 包未正确加载

azure - 如何重试 ADF 管道执行,直到满足条件

c# - 我们是否有 Azure Blob 文件名不支持的字符列表?

powershell - 在WMI查询过滤器中转义美元符号