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
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.
Please check if
AzureAD
module is there or not by running below command:If it still exists, try to uninstall it with below command:
After uninstalling
AzureAD
module , now installAzureADPreview
module and import it like below:Please note that,
AzureADPreview
module won’t work ifAzureAD
module exists.I tried to reproduce the same in my environment and got the response successfully like below:
Response:
I do agree with GauravMantri, if you are working on Mac.