azure - 提取过去 7 天内的所有 Azure Active Directory (AAD) 登录

标签 azure powershell azure-active-directory azure-powershell

我正在尝试在 azure runbook 中获取过去 7 天内的最后一次登录日志,我尝试过以下代码:

$SetDate = (Get-Date).AddDays(-7);
$SetDate = Get-Date($SetDate) -format yyyy-MM-dd
$array = Get-AzureADAuditSignInLogs -Filter "createdDateTime gt $SetDate" | select userDisplayName, userPrincipalName, appDisplayName, ipAddress, clientAppUsed, @{Name = 'DeviceOS'; Expression = {$_.DeviceDetail.OperatingSystem}},@{Name = 'Location'; Expression = {$_.Location.City}}

$array

但它不起作用,它向我显示一条错误消息,其中显示:

System.Management.Automation.CommandNotFoundException: 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.

有人可以帮忙吗?

最佳答案

请通过运行以下命令检查 AzureAD 模块是否存在:

Get-Module -Name AzureAD

如果它仍然存在,请尝试使用以下命令卸载它:

Uninstall-Module AzureAD  

卸载AzureAD模块后,现在安装AzureADPreview模块并导入它,如下所示:

Install-Module AzureADPreview 

Import-Module AzureADPreview 

请注意,如果 AzureAD 模块存在,AzureADPreview 模块将无法工作。

我尝试在我的环境中重现相同的内容并成功获得响应,如下所示:

$SetDate = (Get-Date).AddDays(-7);  
$SetDate = Get-Date($SetDate) -format yyyy-MM-dd  
$array = Get-AzureADAuditSignInLogs -Filter "createdDateTime gt $SetDate" | select userDisplayName, userPrincipalName, appDisplayName, ipAddress, clientAppUsed, @{Name = 'DeviceOS';  
Expression = {$.DeviceDetail.OperatingSystem}},@{Name = 'Location'; Expression = {$.Location.City}}  
$array  

回应:

enter image description here

如果您在 Mac 上工作,我确实同意 GauravMantri 的观点。

关于azure - 提取过去 7 天内的所有 Azure Active Directory (AAD) 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73445021/

相关文章:

regex - 如何找到所有 .git\config 文件?

powershell - 将具有动态元素数量的数组传递到Powershell中的Start-Job中

function - 从 powershell 为 azure 函数创建函数键

azure - 有什么方法可以让azure VM保持相同的IP地址吗?

powershell - 如何根据 azure 命令的输出在 powershell 中拆分字符串

azure - 无法使用服务主体通过 Fluent .NET API 访问 Azure 资源管理器

azure - 有人可以解释一下 Azure AD 应用程序访问和刷新 token 的超时和验证吗?

node.js - Azure AD - 检查安全组成员身份 -(Node.js、passport、Azure Web App)

Azure 表存储删除行键位于两个行键值之间的位置

json - Oracle JSON 交付到 Azure