skip to Main Content

I am trying to get the last sign in logs in the past 7 days in the azure runbook, I have tried this code:

$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

but its not working it shows me an error msg which says:

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.

could anyone help ?

2

Answers


  1. The reason you are getting the error is because Mac is not supported for Azure AD PowerShell Cmdlets.

    You would need to use one of the supported operating systems mentioned here: https://learn.microsoft.com/en-us/powershell/azure/active-directory/install-adv2?view=azureadps-2.0#supported-operating-systems.

    Login or Signup to reply.
  2. Please check if AzureAD module is there or not by running below command:

    Get-Module -Name AzureAD
    

    If it still exists, try to uninstall it with below command:

    Uninstall-Module AzureAD  
    

    After uninstalling AzureAD module , now install AzureADPreview module and import it like below:

    Install-Module AzureADPreview 
    
    Import-Module AzureADPreview 
    

    Please note that, AzureADPreview module won’t work if AzureAD module exists.

    I tried to reproduce the same in my environment and got the response successfully like below:

    $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  
    

    Response:

    enter image description here

    I do agree with GauravMantri, if you are working on Mac.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search