Prerequisites
- Ensure that PowerShell ISE or a PowerShell terminal is opened with Administrator privileges.
- The system should have the necessary access permissions to monitor the specified folders and process.
- Modify the script to suit your environment by adjusting paths, process names, and other configurations as needed.
How to run the script
- Open PowerShell ISE or PowerShell as Administrator:
- Right-click the PowerShell ISE or terminal icon and select “Run as Administrator”.
- Copy and Paste the Script:
- Copy the entire script below into PowerShell ISE or your preferred editor.
- Modify Variables (if needed):
- $logPath: Path to the directory where logs will be stored. Change this as required.
- $processName: The process name you want to monitor (without .exe).
- $foldersToMonitor: List of folders to monitor for file changes. You can add more folder paths as needed.
- $logSizeLimit: Size limit for log files (default is 1MB, adjust as needed).
- $maxRunTimeHours: The maximum number of hours the script will run for process monitoring.
- Run the Script:
- Press the “Run” button or press F5 in PowerShell ISE to execute the script.
- Stopping the Script:
- The script runs indefinitely, monitoring the process and folders until you manually stop it.
- To stop the script, press Ctrl+C in the PowerShell terminal.
Key features of the script
- Process Monitoring:
- The script monitors a process (like cloudmeteringhost) for its activity, including CPU and memory usage.
- The log entry includes the process ID, CPU usage, and memory usage.
- If the process is not running, it logs that the process is not found.
- The script runs for a maximum of $maxRunTimeHours (2 hours by default), after which it stops.
- Folder Monitoring:
- The script monitors specified folders for file creation, deletion, and modification events.
- It captures and logs the timestamp, file path, and type of file operation.
- Monitoring includes subdirectories as well.
- Log File Handling:
- All log entries are saved in a log directory defined by $logPath.
- Log files are named based on the current date (ISO format yyyy-MM-dd).
- If a log file exceeds the size limit (1MB by default), it is rotated, and a new log file with a timestamp is created.
- At the start of each new day, a new log file is created.
Sample Use Cases
- System Admin: Monitor a critical system process and track if it crashes or stops working.
- File Monitoring: Keep track of any changes in sensitive directories for auditing purposes.
- Long-Running: Processes: Automatically stop monitoring after a certain period (e.g., 2 hours).
PowerShell Script
# Define the common log folder path
$logPath = "C:\Logs\CloudMeteringLog" #<<<<<< Change path as needed >>>>>>
# Define the log file size limit in bytes (1MB = 1048576 bytes)
$logSizeLimit = 1048576 #<<<<<< 1 MB, adjust as required >>>>>>
# Define the process name to monitor
$processName = "cloudmeteringhost" #<<<<<< Change process name (without .exe) >>>>>>
# Define the folder paths to monitor
$foldersToMonitor = @(
"C:\ProgramData\SnowSoftware\Inventory\Agent\cloudmetering\logs",
"C:\Program Files\Snow Software\Inventory\Agent"
)
# Maximum runtime for process monitoring in hours
$maxRunTimeHours = 2
# Function to create log folder if it doesn't exist
function Ensure-LogFolder {
if (!(Test-Path -Path $logPath)) {
New-Item -Path $logPath -ItemType Directory
Write-Host "Log folder created: $logPath"
}
}
# Function to rotate log files (by size or new day)
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-ddTHH-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"
}
$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
$logFileName = (Get-Date -Format "yyyy-MM-dd") + "-FileLog.txt"
$logFilePath = Join-Path -Path $logPath -ChildPath $logFileName
Add-Content -Path $logFilePath -Value $logEntry
}
# Event: File created
$createdEventAction = {
$folder = $Event.SourceEventArgs.FullPath
$file = $Event.SourceEventArgs.Name
$timestamp = Get-Date -Format "yyyy-MM-ddTHH:mm:ss"
$logEntry = "$timestamp - New file created in ${folder}: ${file}"
LogOutput -logEntry $logEntry
}
# Event: File deleted
$deletedEventAction = {
$folder = $Event.SourceEventArgs.FullPath
$file = $Event.SourceEventArgs.Name
$timestamp = Get-Date -Format "yyyy-MM-ddTHH:mm:ss"
$logEntry = "$timestamp - File deleted from ${folder}: ${file}"
LogOutput -logEntry $logEntry
}
# Event: File modified
$modifiedEventAction = {
$folder = $Event.SourceEventArgs.FullPath
$file = $Event.SourceEventArgs.Name
$timestamp = Get-Date -Format "yyyy-MM-ddTHH:mm:ss"
$logEntry = "$timestamp - File modified in ${folder}: ${file}"
LogOutput -logEntry $logEntry
}
# Function to start monitoring folders for file changes
function Start-MonitoringFolders {
foreach ($folder in $foldersToMonitor) {
$watcher = New-Object System.IO.FileSystemWatcher
$watcher.Path = $folder
$watcher.IncludeSubdirectories = $true
$watcher.EnableRaisingEvents = $true
Register-ObjectEvent -InputObject $watcher -EventName "Created" -Action $createdEventAction
Register-ObjectEvent -InputObject $watcher -EventName "Deleted" -Action $deletedEventAction
Register-ObjectEvent -InputObject $watcher -EventName "Changed" -Action $modifiedEventAction
Write-Host "Started monitoring folder: $folder"
}
}
# Function to monitor process activity
function Monitor-Process {
$startTime = Get-Date
while ($true) {
RotateLogFile
$timestamp = Get-Date -Format "yyyy-MM-ddTHH:mm:ss"
$elapsedTime = (Get-Date) - $startTime
$elapsedHours = $elapsedTime.TotalHours
if ($elapsedHours -ge $maxRunTimeHours) {
Write-Host "Script reached max runtime of $maxRunTimeHours hours. Exiting."
break
}
$processInfo = Get-Process -Name $processName -ErrorAction SilentlyContinue |
Select-Object Id, ProcessName, CPU, WorkingSet
if ($processInfo) {
$logEntry = "$timestamp - Id: $($processInfo.Id), Name: $($processInfo.ProcessName), CPU: $($processInfo.CPU), Memory: $($processInfo.WorkingSet)"
LogOutput -logEntry $logEntry
} else {
$logEntry = "$timestamp - Process $processName is not running."
LogOutput -logEntry $logEntry
}
Start-Sleep -Seconds 5
}
}
# Main Function to Start All Monitoring
function Start-AllMonitoring {
Ensure-LogFolder
Start-MonitoringFolders
Monitor-Process
}
# Initialize previous day variable
$global:previousDay = Get-Date -Format "yyyy-MM-dd"
# Start the combined monitoring script
Start-AllMonitoring
Write-Host "Logging to: $logPath. Press Ctrl+C to stop the script."Was this helpful?
Related Articles
Logging An InstallScript MSI Project 360Number 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