Home > Software engineering >  How to get-date automatically in AzureADAuditDirectoryLogs
How to get-date automatically in AzureADAuditDirectoryLogs

Time:11-23

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:

enter image description here

File:

After command runned successfully you can view the csv file which is stored in your local path.

enter image description here

Reference: Get-AzureADAuditDirectoryLogs (AzureADPreview) | Microsoft Learn

  • Related