Sharepoint 2016 audit

Copper Contributor

Good afternoon.

Please tell me about the PowerShell script. I'm still not good at understanding.

There is a standard report, site settings\site collection administration\audit log report\custom report launch, where you can select the desired user, select the desired query, select for what period of time you want to receive a report. In fact, I need everything the same only through Powershell.

Found this example:

# Prompt the user to enter the URL of the web;
$webURL = http://test-portal.portal.ru

# Prompt the user for the name of the document library containing the document;
$docLibraryName = "testdocuments01"

# Prompt the user to enter the URL to the document;
$docURL = Read-Host "URL of the document"

# Get a reference to the document in question;
$web = Get-SPWeb $webURL
$docLibrary = $web.Lists[$docLibraryName]
$document = $web.GetFile($docURL)
$web.Dispose()

# Get the audit entry for the library;
$audit = $docLibrary.Audit
$auditEntries = $audit.GetEntries()

foreach($entry in ($auditEntries | Select -unique))
{
      $userId = $entry.UserId
      $userEntry = $web.AllUsers | Where{$_.ID -eq $userId}
      $userName = $userEntry.UserLogin
      Write-Host $userName "--" $entry.Occurred "--" $entry.Event
}

 

Displays information:

i:0#.w|domen\user01 -- 02.02.2022 10:14:27 -- View
i:0#.w|domen\user01 -- 02.02.2022 10:14:45 -- Update

 

On the whole, I am almost satisfied with this conclusion.

And I need for a specific file, not for all documents in the document library. And append to this output "i:0#.w|domen\user01 -- 02/02/2022 10:14:27 -- View" the name of the document, including documents located in subfolders in the $docLibraryName document library.

Can you tell me how to write?

 

0 Replies