Blog Post

Apps on Azure Blog
1 MIN READ

PowerShell script to list all running processes in your Azure AppService (w/Computer name)

Prashant Pratap's avatar
Apr 02, 2019
First published on MSDN on Jun 26, 2018


Here is a quick PowerShell scripts to get list of all websites in your Azure Subscription, along with the processes running within each website.

This script also print the VM Instance ID and VM machine Name. Here is the sample output :



[code language="powershell"]

Login-AzureRmAccount


$websites = Get-AzureRmResource -ResourceType Microsoft.Web/sites

foreach($website in $websites)
{
$resoureGroupName = $website.ResourceGroupName
$websiteName = $website.Name

Write-Host "Website : " -ForegroundColor Blue -NoNewline
Write-Host $websiteName -ForegroundColor Red -NoNewline
Write-Host " in ResourceGroup : " -ForegroundColor Blue -NoNewline
Write-Host $resoureGroupName -ForegroundColor Red

$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 "`tVM Instance ID : " $instanceName

try
{
$processes = Get-AzureRmResource -ResourceGroupName $resoureGroupName `
-ResourceType Microsoft.Web/sites/instances/processes `
-ResourceName $websiteName/$instanceName `
-ApiVersion 2018-02-01 `
-ErrorAction Ignore
}
catch
{
continue
}


foreach($process in $processes)
{
$exeName = $process.Properties.Name
Write-Host "`t`tEXE Name `t`t: " $exeName

$processId = $process.Properties.id
Write-Host "`t`t`tProcess ID `t: " $processId

try {
$processDetails = Get-AzureRmResource -ResourceGroupName $resoureGroupName `
-ResourceType Microsoft.Web/sites/instances/processes `
-ResourceName $websiteName/$instanceName/$processId `
-ApiVersion 2018-02-01 `
-ErrorAction Ignore


Write-Host "`t`t`tFile Name `t: " $processDetails.Properties.file_name
Write-Host "`t`t`tCMD Line `t: " $processDetails.Properties.command_line
Write-Host "`t`t`tComputer Name `t: " $processDetails.Properties.environment_variables.COMPUTERNAME

}
catch {

}

}
}
}
[/code]
Updated Aug 24, 2020
Version 2.0

1 Comment

  • drckmn's avatar
    drckmn
    Copper Contributor

    I've been tring to find a way to do this - thank you!