I want to automate a task to download my azure ad audit logs on daily basis. Can i use the Get-date in the below command instead of entering the mannual data.
Get-AzureADAuditDirectoryLogs -Filter "activityDateTime gt 2019-03-20" | Export-Csv c:\auditlogs.csv
CodePudding user response:
I tried in my environment and got results successfully.
Please check the below code which I tried,
Here I used get-date -Format "yyyy-MM-dd"
to get the correct format of the get-date.
Code:
$date = get-date -Format "yyyy-MM-dd"
Get-AzureADAuditDirectoryLogs -Filter "activityDateTime gt $date" | Export-Csv -Path "< Path to store >"
Console:
File:
After command runned successfully you can view the csv file which is stored in your local path.
Reference: Get-AzureADAuditDirectoryLogs (AzureADPreview) | Microsoft Learn