How do I start a process from Powershell with job object attached to it limiting its…
- User
How do I start a process from Powershell with job object attached to it limiting its memory usage to 50 MB?
Assistant
powershell# Define the process to start $processName = "notepad.exe" # Create a new job object $job = New-Object System.Management.Automation.Job # Set the memory limit for the job $job.LimitJobMemory = 50MB # Start the process as a job $process = Start-Process -FilePath $processName -Job $job # Wait for the process to complete $process.WaitForCompletion() # Check the exit code if ($process.ExitCode -eq 0) { Write-Host "Process completed successfully." } else { Write-Host "Process failed with exit code $($process.ExitCode)." }