Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Documentation update Get-PnPUnifiedAuditLog Start and end times should be UTC Dates. #3753

Closed
SPDEVGUY opened this issue Feb 14, 2024 · 7 comments · Fixed by #3785
Closed
Labels
bug Something isn't working

Comments

@SPDEVGUY
Copy link

Reporting an Issue or Missing Feature

Bug (Documentation incorrect)

https://pnp.github.io/powershell/cmdlets/Get-PnPUnifiedAuditLog.html

Example 1
Get-PnPUnifiedAuditLog -ContentType SharePoint -StartTime (Get-Date).AddDays(-2) -EndTime (Get-Date).AddDays(-1)

Expected behavior

Documentation is missing the fact that start and end times are UTC.

Actual behavior

Example 1 should be like this and Start and End times documentation should make note that dates provided are UTC times.

$utcNow = Get-Date -asUtc
Get-PnPUnifiedAuditLog -ContentType SharePoint -StartTime ($utcNow).AddDays(-2) -EndTime ($utcNow).AddDays(-1)

@SPDEVGUY SPDEVGUY added the bug Something isn't working label Feb 14, 2024
@gautamdsheth
Copy link
Collaborator

@reshmee011 - can you check this since you recently worked on some improvements around this ? When we first created this cmdlet, we didn't require dates to be in UTC , but maybe things have changed ?

@reshmee011
Copy link
Contributor

@gautamdsheth , that's right the date and times need to be in UTC, I discovered it while working with cli for m365 equivalent as the dates are being passed as string and needed to be formatted to ISO 8601 string (2024-02-16)
https://pnp.github.io/cli-microsoft365/cmd/purview/auditlog/auditlog-list/
Get-Date -uFormat '%Y-%m-%d'

The PnP PowerShell accepts date parameters , hence conversion not required.
https://reshmeeauckloo.com/posts/powershell-get-log-sharepoint-dlp-exchange-entra-pnpunifiedlog/

Worth mentioning the required format.

@gautamdsheth
Copy link
Collaborator

@reshmee011 - thanks for confirming ! Could you also please update the PR as well to mention this ? :)

@reshmee011
Copy link
Contributor

@gautamdsheth : I have updated the PR to include the note about passing the start and end date in ISO 8601 format if passed as string format.

gautamdsheth added a commit that referenced this issue Feb 16, 2024
* updates

* Added the permissions set in the cmdlet and docs

* Update doc for #3753

* update

---------

Co-authored-by: Gautam Sheth <[email protected]>
@gautamdsheth
Copy link
Collaborator

Thanks @SPDEVGUY and @reshmee011 , docs updated. Closing this.

@SPDEVGUY
Copy link
Author

@gautamdsheth / @reshmee011
The command accepting the dates should also point out that the date objects passed to the command should be UTC based.

$forDay = (Get-date)
$fromDate = Get-Date -Year ($forDay.Year) -Month ($forDay.Month) -Day ($forDay.Day) -hour 0 -minute 0 -second 0 -millisecond 0
$toDate = $fromDate.AddMinutes(60)


$fromDateUtc = get-date -date ($fromDate) -asUtc
$toDateUtc = get-date -date ($toDate) -asUtc

Get-PnPUnifiedAuditLog -ContentType SharePoint -StartTime $fromDateUtc -EndTime $toDateUtc

<# Will not return the same as  #>

Get-PnPUnifiedAuditLog -ContentType SharePoint -StartTime $fromDate -EndTime $toDate

In order to get the actual latest entries (which my app follows in 5 min slices) I needed to use the utc time now less 5 mins to actually get things that happened in the last 5 minutes.

You could probably just make this clear by changing your example to include " -asUtc"

Get-PnPUnifiedAuditLog -ContentType SharePoint -StartTime (Get-Date -asUtc).AddDays(-2) -EndTime (Get-Date -asUtc).AddDays(-1)

image

@reshmee011
Copy link
Contributor

I apologize for any inconvenience caused by the oversight. As I am based in the UK and use GMT, I didn’t fully appreciate the impact of non-UTC dates. Thank you for bringing this to my attention! 😊. I have submitted a PR to update the docs.

gautamdsheth pushed a commit that referenced this issue Feb 23, 2024
* Updating the docs to specify that start and end time needs to be UTC

* Update audit log docs

* update docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants