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

1 year, 1 month ago.

  • Author
  • #97656

    Topics: 1
    Replies: 0
    Points: 0
    Rank: Member

    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}
    {Nothing found}

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

  • #97668

    Topics: 13
    Replies: 48
    Points: 0
    Rank: Member

    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

    Topics: 2
    Replies: 428
    Points: 835
    Helping Hand
    Rank: Major Contributor

    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.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort