This could be useful for tracking any temporary files such as web metering to understand what files are being generated, but could be useful for any general troubleshooting.
##
#Description:
#Log the files written in a folder path.
#
# Version: 1.1
# Updated: 20231121
# Author: Julian Dalley
# Change: Added limit to log file size, and day roll for log, now logs deleted files.
###
###<<<<RUN IN POWERSHELL ISE AS ADMINISTRATOR>>>>###
# Define the folder path to monitor
$folderToMonitor = "C:\Temp"
# Define the log file path and size limit (in bytes)
$logPath = "C:\File\Logfolder"
$logSizeLimit = 1048576 # 1 MB (adjust as needed)
# Create a FileSystemWatcher to monitor the folder and subfolders
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = $folderToMonitor
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $true
# Function to check and rotate log file if size limit is reached or new day begins
function RotateLogFile {
$currentDate = Get-Date -Format "yyyy-MM-dd"
$logFileName = $currentDate + "-FileLog.txt"
$logFilePath = Join-Path -Path $logPath -ChildPath $logFileName
if ((Test-Path -Path $logFilePath) -and ((Get-Item $logFilePath).length -ge $logSizeLimit)) {
$newLogFileName = (Get-Date -Format "yyyy-MM-dd_HH-mm-ss") + "-FileLog.txt"
$newLogFilePath = Join-Path -Path $logPath -ChildPath $newLogFileName
Rename-Item -Path $logFilePath -NewName $newLogFileName
Write-Host "Log file rotated. New log file created: $newLogFilePath"
}
# Check if a new day has started
$currentDay = Get-Date -Format "yyyy-MM-dd"
if ($currentDay -ne $global:previousDay) {
$global:previousDay = $currentDay
$newLogFileName = $currentDay + "-FileLog.txt"
$newLogFilePath = Join-Path -Path $logPath -ChildPath $newLogFileName
if (!(Test-Path -Path $newLogFilePath)) {
New-Item -Path $newLogFilePath -ItemType File -Force
Write-Host "New day started. Created new log file: $newLogFilePath"
}
}
}
# Function to log output to console and file
function LogOutput {
param (
[string]$logEntry
)
Write-Host $logEntry
RotateLogFile
# Define the log file name with an ISO date
$logFileName = (Get-Date -Format "yyyy-MM-dd") + "-FileLog.txt"
$logFilePath = Join-Path -Path $logPath -ChildPath $logFileName
# Append the log entry to the log file
Add-Content -Path $logFilePath -Value $logEntry
}
# Define the event to trigger when a new file is created
$createdEventAction = {
$file = $Event.SourceEventArgs.Name
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$logEntry = "$timestamp - New file created: $file"
# Log output for created file
LogOutput -logEntry $logEntry
}
# Define the event to trigger when a file is deleted
$deletedEventAction = {
$file = $Event.SourceEventArgs.Name
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
$logEntry = "$timestamp - File deleted: $file"
# Log output for deleted file
LogOutput -logEntry $logEntry
}
# Register the events for created and deleted files
Register-ObjectEvent -InputObject $watcher -EventName "Created" -Action $createdEventAction
Register-ObjectEvent -InputObject $watcher -EventName "Deleted" -Action $deletedEventAction
# Start an infinite loop to keep the script running
Write-Host "Monitoring folder: $folderToMonitor"
Write-Host "Logging to: $logPath"
Write-Host "Press Ctrl+C to exit."
# Initialize previous day variable
$global:previousDay = Get-Date -Format "yyyy-MM-dd"
while ($true) {
Start-Sleep -Seconds 1
}
Was this helpful?
Related Articles
PowerShell script to monitor the process and folders used by the cloud metering process 73Number of Views FlexNet agent (ndtrack) may trigger a security software warning due to PowerShell script execution containing unusual char… 74Number of Views PowerShell script to delete the Snow MongoDB service 5Number of Views FlexNet Manager Suite log files and locations 182Number of Views PowerShell script to identify folders exceeding specified size 5Number of Views
Revenera Assistant
Online
Hi, I am Reva - Ask me anything.
Updates
No new updates
Chat
Home
Updates
/**/
Thanks for the feedback!
Your feedback has been saved.Rate this response:
1
2
3
4
5
Add Additional feedback ( Optional )
0/240
English
English
Language changed successfully
Something went wrong
Email sent successfully
Something went wrong
Case create successfully
Are you sure you want to cancel
the case creation?
Please select a product to submit the case.
Please select a product version to submit the case.
0/255
Upload Attachment
File Upload
Maximum file
size allowed is 3 MB.
File type
not supported.
Supported file types:
Documents (.txt, .doc, .docx, .pdf), Images (.jpg, .png), Comma Separated Files
(.csv) Speadsheets (.xlsx, .xls)
Are you sure you want to cancel the case creation?
Case closed successfully
File Upload
Maximum file size allowed is 3 MB.
File type not supported.
Supported file types:
Documents (.txt, .doc, .docx, .pdf), Images (.jpg, .png), Comma Separated Files
(.csv) Speadsheets (.xlsx, .xls)
Are you sure you want to close this case
| Products | Region | Phone Numbers |
|---|---|---|
| FlexNet Operations FlexNet Embedded FlexNet Publisher FlexNet Connect FlexNet Code Insight InstallAnywhere InstallShield |
North America * |
+1 630-332-2513 (toll) +1 877-279-2853 (toll-free in North America) |
| Europe * |
+44 1925 944367 (toll) +44 800 047 8642 (toll-free in Europe) |
|
| Japan * | +81 3-4540-5335 (select option 2) | |
| Australia * |
+61 3 9895 2177 +61 1800 560 603 (toll-free in Australia) |
|
|
Usage Intelligence (formerly
Revulytics) Compliance Intelligence |
Please use the Case Portal to submit your support ticket or reach out to your Revenera contact. | |
File Upload
Maximum file
size allowed is 3 MB.
File type
not supported.
Supported file types:
Documents (.txt, .doc, .docx, .pdf), Images (.jpg, .png), Comma Separated Files
(.csv) Speadsheets (.xlsx, .xls)
© 2026 Flexera Software. All Rights Reserved.
Case id: 00001065
Activity: Status change: 2 hours ago