0

I updated PS 1.0 to 4.0 and my script is not working.

It says:

Method invocation failed because [System.Object[]] does not contain a method na
med 'op_Division'.
At C:\Users\sabrnpet\Documents\rsm-monitoring-killer.ps1:18 char:5
+ if ($test/1KB -ge $consumed)
+     ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (op_Division:String) [], Runti 
   meException
    + FullyQualifiedErrorId : MethodNotFound

Here is script:

### EDIT ME ####
$process = "opera" # BMCRSM
$consumed = 4500000 # in kilobytes
################

# checking if process is running
if (-not (Get-Process $process -ea 0) )
{
    Write-Host "Process $process is not running"
    Exit
}

# variables
$getProcess = Get-Process $process 

# checking if process eating much ram
if ($getProcess.WorkingSet64/1KB -ge $consumed)
{
    Write-Host "I will termiante it..."
    $getProcess.Kill()
}
else
{
    Write-Host "OK"
}

I undestand that there is problem with divison of kilobytes I think, but I need this value in kilobytes. So how to do It please?

Thanko you

2 Answers 2

1

Look at your error message:

Method invocation failed because [System.Object[]] does not contain a method named 'op_Division'.

[System.Object[]] denotes an array. Get-Process is finding more than one instance of Opera running. You need to iterate through that array, and work on them one at a time:

# checking if process eating much ram

Foreach ($FoundProcess in $getProcess)
  {
   if ($FoundProcess.WorkingSet64/1KB -ge $consumed)
   {
    Write-Host "I will termiante it..."
    $FoundProcess.Kill()
   }


  else
  {
    Write-Host "OK"
  }
}
Sign up to request clarification or add additional context in comments.

Comments

0

I got it:

# variables
$getProcess = Get-Process "$process"

string variable must be in "quotes"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.