Compare 2 values and perform action

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?

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'

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