Direct Inward Dialing: +1 408 916 9892
Beyond ensuring compliance, monitoring file activity helps IT administrators detect unauthorized changes, investigate suspicious activity, and respond to potential insider or external threats.
For Windows Security to record the events of file or folder activities, file auditing policies and object-level auditing must be enabled.
To get the last modified file in a directory, file auditing policies must be enabled at the GPO level and at file/folder level. Once enabled, such file modifications are recorded as an event, which can be viewed using EventViewer.
Follow the steps below to enable file auditing policies in the Group Policy Management Console (GPMC):
Creating a separate GPO makes it easier to troubleshoot, manage, and modify auditing configurations without affecting other domain-wide policies.
Audit object access is a specific audit subcategory. When enabled, it triggers Windows to start generating security log events, which are further collected by Event Viewer.
Once auditing is configured, Windows records relevant file system activity through Event ID 4663. Event ID 4663- An attempt was made to access an object is generated when a particular operation is performed on an AD object such as file/folder. Tracking this eventID helps in identifying activities such as Read, Write, Delete or Moved. This eventID shall be tracked using the EventViewer.
The below PowerShell command sample returns the file name, last modification time, and file size of the most recently modified file.
The configuration of audit policies in GPMC and object-level auditing is not required when executing PowerShell commands.
Get-ChildItem -Path "C:\YourFolder" -File |
Sort-Object LastWriteTime -Descending |
Select-Object -First 1 |
Select-Object Name, LastWriteTime, Length
Below are some limitations faced when tracking who last modified a file using native auditing and PowerShell commands:
With the help of a centralized auditing solution like ADAudit Plus, administrators can monitor, investigate, and respond to file modifications more efficiently than native auditing and PowerShell methods.
To track the last modified a file in a directory with ADAudit Plus:
With Advanced Search in each report, a filtered search of all file activities across the environment can be performed at once. Through this feature, you can view a complete audit trail of files from a specific directory or by a specific date and time range.
Additionally, ADAudit Plus offers customized reports, scheduled reporting, and real-time notifications to alert when changes are performed on critical files.
The below PowerShell command retrieves the last modified file in a directory that has multiple subfolders. It returns the name of the file modified, last modified timestamp, length of the file after modification, and its relative path.
Get-ChildItem -Path "C:\YourFolder" -File -Recurse |
Sort-Object LastWriteTime -Descending |
Select-Object -First 1 |
Select-Object Name, LastWriteTime, Length, DirectoryName
With ADAudit Plus
$path = "C:\YourFolder"
Get-ChildItem -Path $path -Directory | ForEach-Object {
Get-ChildItem -Path $_.FullName -File -Recurse |
Sort-Object LastWriteTime -Descending |
Select-Object -First 1 |
Select-Object @{l='Folder';e={$_.DirectoryName}}, Name, LastWriteTime, Length
}
With ADAudit Plus
$path = "C:\YourFolder"
Get-ChildItem -Path $path -File -Recurse |
Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-1) } |
Sort-Object LastWriteTime -Descending |
Select-Object Name, LastWriteTime, Length, DirectoryName
Change AddDays(-1) to your required number of days. For example: Use AddDays(-7) to receive the most recently modified files from the last seven days or AddDays(-30) for the last 30 days.
With ADAudit Plus
Get-ChildItem is a built-in PowerShell cmdlet that retrieves the list of items, such as files or folders, within one or more specified locations.
For example, Get-ChildItem -Path "C:\ADAudit Plus" lists all the files and sub directories within the ADAudit Plus folder.
Not necessarily. PowerShell commands are used to get the last modified file in a directory without enabling group policies or auditing entries. See the section on tracking the last modified file using PowerShell for sample commands.
Event ID 4663 is used to track file modifications. However, this Event ID is also generated whenever an action is performed on an object, such as a kernel or a file system object via a removable storage device.