1

I use power shell script to find a process with its command line name.But when i run the script,cpu usage of the machine is increasing about 10 percent.I don't want this kind of increase amount.Below code scripts is increasing cpu usage

$wmiComParams=Get-WmiObject win32_process -Filter "CommandLine like '%$appWmi%'" | select CommandLine

Is there any other solution for this problem ?

nihasmata
  • 652
  • 1
  • 8
  • 28

1 Answers1

0

I'm not a power shell user though I might have to learn soon enough. I can make some general observations.

When launching a script, a new process is spun off. Launching any heavy weight process is going to take up CPU cycles. If your application / script is short, it's very likely that most of your CPU time is taken by launching/tear-down.

Similarly, a script itself typically launches a whole host of other processes as different commands are executed. This means even more CPU cycles are taken up in setup and tear down of your processes.

Here are some suggestions: Use control structures that are built into power shell instead of separate apps whenever possible. Power shell control structures should not launch another process, thus avoiding the setup/tear-down time I mentioned. Try to execute processes/applications as few times as possible. For example (using my native Linux dialect): BIG-APP < entire-file versus for each line do SMALL-APP one-line.

Taylor Kidd
  • 1,463
  • 1
  • 9
  • 11