write a powershell 4 script which receives an array of process names, and make sure all…
- User
write a powershell 4 script which receives an array of process names, and make sure all processes are running on the system. for efficiency, the system should be queried for all running processes only once
- Assistant
Here is a sample PowerShell script that receives an array of process names and checks if all the processes are running on the system:
code# Query the system for a list of running processes $processes = Get-Process # Loop through the array of process names foreach ($processName in $args) { # Check if the process is running if ($processes.Name -contains $processName) { Write-Output "$processName is running" } else { Write-Output "$processName is not running" } }To use this script, save it to a file with a
.ps1extension, then run it from the PowerShell command line, passing in the array of process names as arguments. For example:code.\check-processes.ps1 -args "process1", "process2", "process3"This script is for PowerShell 4, so it should work on any system that has PowerShell 4 or a later version installed.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.