PowerShell: last accessed date/time of the file

Justinas 25 Reputation points
2023-12-01T08:58:09.5633333+00:00

Hello,

we're using loads of SharePoint sites that consume enough space in our tenant, thus we're trying to filter out files' usage, and in this case we need to get last access date of the files through PowerShell.

Currently on SharePoint site level we've enabled "SharePoint viewer" feature which enables option to view last access date on SharePoint site, but this property is missing in the PowerShell during the file's field values retrieve.

Previously there was a possibility to retrieve last access date using SPO-Services method 'Get-SPOFile' but now it's not supported/gone.

Could you tell please, is there a possibility to get last access date or is it planned to integrate this property/method in the back-end (PowerShell)?

Thank you!

Microsoft 365 and Office SharePoint For business Windows
Windows for business Windows Server User experience PowerShell
0 comments No comments
{count} votes

Accepted answer
  1. AllenXu-MSFT 24,941 Reputation points Moderator
    2023-12-04T03:05:35.02+00:00

    Hi @Justinas,

    Currently I'm afraid it's impossible to retrieve last access date of files through PowerShell.

    As a workaround, you can use the Get-PnPFile cmdlet from the SharePoint PnP PowerShell module. This cmdlet provides the TimeLastModified property, which represents the last time the file was modified or accessed. Here's an example command to retrieve the last access date of a file:

    Connect-PnPOnline -Url https://yourtenant.sharepoint.com/sites/yoursite
    $file = Get-PnPFile -Url "/sites/yoursite/Shared Documents/yourfile.docx"
    $file.TimeLastModified
    
    
    

    Also, you can go to Microsoft Purview >> Audit >> Specify a file name and search for file access records from the recent period to the current time.User's image


    If the answer is helpful, please click "Accept as Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.