This script will be useful if you want to monitor if a process is frozen or not. The process manage files in a specific location (read, write and delete). The purpose is :
- check the number of files in the working directory of the process
- check the process “WriteTranferCount” information to see if the process is not frozen
If the process monitor detects a frozen status, a mail is sent
Script :
if (((Get-ChildItem "\\server\path\process_working_directory").count) -gt 1) {
if (Test-Path "c:\temp\process-chk.log") {
$previous_value = Get-Content "c:\temp\process-chk.log"
}
$new_value = Get-WmiObject Win32_Process -ComputerName "server" | `
where {$_.Name -eq 'processName.exe'} | `
foreach {"$($_.WriteTransferCount)"}
if ($new_value -ne $previous_value) {
Write-Host "Process OK"
}
else {
$message_success = "The process on the server is frozen."
$emailFrom = "support@mail.domain.local"
$emailTo = "'support@mail.domain.local','johndoe@mail.domain.local'"
$subject = "PROBLEM : SERVER PROCESS NAME FROZEN"
$smtpServer = "smtp_default"
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
$smtp.Send($emailFrom, $emailTo, $subject, $message_success)
}
$new_value | Out-File "c:\temp\process-chk.log" -Force
}
Reference
Win32_Process class
The Win32_Process WMI class represents a process on an operating system.
The following syntax is simplified from Managed Object Format (MOF) code and includes all of the inherited properties.
Syntax
[Provider("CIMWin32")]class Win32_Process : CIM_Process
{
string Caption;
string CommandLine;
string CreationClassName;
datetime CreationDate;
string CSCreationClassName;
string CSName;
string Description;
string ExecutablePath;
uint16 ExecutionState;
string Handle;
uint32 HandleCount;
datetime InstallDate;
uint64 KernelModeTime;
uint32 MaximumWorkingSetSize;
uint32 MinimumWorkingSetSize;
string Name;
string OSCreationClassName;
string OSName;
uint64 OtherOperationCount;
uint64 OtherTransferCount;
uint32 PageFaults;
uint32 PageFileUsage;
uint32 ParentProcessId;
uint32 PeakPageFileUsage;
uint64 PeakVirtualSize;
uint32 PeakWorkingSetSize;
uint32 Priority = NULL;
uint64 PrivatePageCount;
uint32 ProcessId;
uint32 QuotaNonPagedPoolUsage;
uint32 QuotaPagedPoolUsage;
uint32 QuotaPeakNonPagedPoolUsage;
uint32 QuotaPeakPagedPoolUsage;
uint64 ReadOperationCount;
uint64 ReadTransferCount;
uint32 SessionId;
string Status;
datetime TerminationDate;
uint32 ThreadCount;
uint64 UserModeTime;
uint64 VirtualSize;
string WindowsVersion;
uint64 WorkingSetSize;
uint64 WriteOperationCount;
uint64 WriteTransferCount;
};
Monitor if a process is frozen
