Terminate w3wp.exe process without stopping website




First published on MSDN on Jun 20, 2018








Here is a quick way to terminate w3wp.exe process in Azure App Service Website without stopping the whole website.




Note

: Azure AppService website can run on multiple instances and there is another w3wp.exe process called SCM running on each instance (we shouldn’t kill this process). So we just have to get list of all instances running the website using

Get-AzureRMResource

cmdlet. On each instance, we need to get list of processes running using same Get-AzureRMResource cmdlet. Next, we need to check if this process is w3wp.exe process and see if the SCM property is true. Last step is using

Remove-AzureRMResource

to terminate the process.




Azure Resource Explorer

is the best tool that can help us to pick the right PowerShell cmdlet to use and what parameters to pass. Just click on PowerShell tab in the resource explorer as shown below.

















[code language=”powershell”]




Login-AzureRmAccount




$resoureGroupName = “wabac”


$websiteName = “wabacblue”






$instances = Get-AzureRmResource -ResourceGroupName $resoureGroupName `


-ResourceType Microsoft.Web/sites/instances `


-ResourceName $websiteName `


-ApiVersion 2018-02-01






foreach($instance in $instances)


{


$instanceName = $instance.Name




Write-Host “Site Instance Name : ” $instanceName




$processes = Get-AzureRmResource -ResourceGroupName $resoureGroupName `


-ResourceType Microsoft.Web/sites/instances/processes `


-ResourceName $websiteName/$instanceName `


-ApiVersion 2018-02-01




foreach($process in $processes)


{


$exeName = $process.Properties.Name


Write-Host “`tEXE Name : ” $exeName




if($exeName -eq “w3wp”)


{


$processId = $process.Properties.id


Write-Host “`t`tProcess ID : ” $processId




$processDetails = Get-AzureRmResource -ResourceGroupName $resoureGroupName `


-ResourceType Microsoft.Web/sites/instances/processes `


-ResourceName $websiteName/$instanceName/$processId `


-ApiVersion 2018-02-01




Write-Host “`t`tSCM Value : ” $processDetails.Properties.is_scm_site




if($processDetails.Properties.is_scm_site -ne $true)


{


Write-Host “`t`t`tNot a SCM Process : ” $process.Properties.Name




$deleted = Remove-AzureRmResource -ResourceGroupName $resoureGroupName `


-ResourceType Microsoft.Web/sites/instances/processes `


-ResourceName $websiteName/$instanceName/$processId `


-ApiVersion 2018-02-01 -Force




if($deleted -eq $true)


{


Write-Host “`t`t`t`tW3wp process killed” -ForegroundColor Green


}


else


{


Write-Host “`t`t`t`tFailed to kill W3wp process” -ForegroundColor Red


}


}


}


}


}










[/code]

REMEMBER: these articles are REPUBLISHED. Your best bet to get a reply is to follow the link at the top of the post to the ORIGINAL post! BUT you're more than welcome to start discussions here:

This site uses Akismet to reduce spam. Learn how your comment data is processed.