Compare 2 values and perform action

Welcome Forums General PowerShell Q&A Compare 2 values and perform action

This topic contains 2 replies, has 3 voices, and was last updated by

 
Participant
6 months, 2 weeks ago.

  • Author
    Posts
  • #97656

    Participant

    Hi,
    I want to recycle app pool whose pid is found utilizing high memory..
    #Get App pool and Process Id
    $x=Get-WmiObject -NameSpace 'root\WebAdministration' -class 'WorkerProcess'| select AppPoolName,ProcessId
    #Get top 3 process ids utilizing high memory
    $y=Get-Process | Sort-Object -Descending WS| select -first 3|select Id

    Now if ($x.ProcessId is in $y.Id)
    { Find app pools name and recycle}
    else
    {Nothing found}

    I am unable to compare and find the app pool name. Could you please help me?

  • #97668

    Participant

    Hi,
    Please use the

     and the 

    blocks for better understanding,

    (i don't have iis on my machin so i cant test it)

    did you try to run only this and got a proper result?:

    Get-WmiObject -NameSpace 'root\WebAdministration' -class 'WorkerProcess'
  • #97686

    Participant

    You can do:

    $y = Get-Process | Sort-Object -Descending WS |
        Select-Object -First 3 |
        Select-Object -ExpandProperty Id
    
    $x.ProcessID | 
        Where-Object {$_ -in $y} | 
        ForEach-Object {
            #do things with each $_ or $PSItem
        }

The topic ‘Compare 2 values and perform action’ is closed to new replies.