Home
%3CLINGO-SUB%20id%3D%22lingo-sub-392600%22%20slang%3D%22en-US%22%3EPowerShell%20script%20to%20list%20all%20running%20processes%20in%20your%20Azure%20AppService%20(w%2FComputer%20name)%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-392600%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20MSDN%20on%20Jun%2026%2C%202018%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%3E%3CBR%20%2F%3E%3C%2FP%3E%0A%20%20%3CP%3EHere%20is%20a%20quick%20PowerShell%20scripts%20to%20get%20list%20of%20all%20websites%20in%20your%20Azure%20Subscription%2C%20along%20with%20the%20processes%20running%20within%20each%20website.%3C%2FP%3E%0A%20%20%3CP%3EThis%20script%20also%20print%20the%20VM%20Instance%20ID%20and%20VM%20machine%20Name.%20Here%20is%20the%20sample%20output%20%3A%3C%2FP%3E%0A%20%20%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F101205iAA22DE78B1B7914B%22%20%2F%3E%3C%2FP%3E%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%5Bcode%20language%3D%22powershell%22%5D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Login-AzureRmAccount%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%24websites%20%3D%20Get-AzureRmResource%20-ResourceType%20Microsoft.Web%2Fsites%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20foreach(%24website%20in%20%24websites)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20%24resoureGroupName%20%3D%20%24website.ResourceGroupName%20%3CBR%20%2F%3E%20%24websiteName%20%3D%20%24website.Name%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Write-Host%20%22Website%20%3A%20%22%20-ForegroundColor%20Blue%20-NoNewline%20%3CBR%20%2F%3E%20Write-Host%20%24websiteName%20-ForegroundColor%20Red%20-NoNewline%20%3CBR%20%2F%3E%20Write-Host%20%22%20in%20ResourceGroup%20%3A%20%22%20-ForegroundColor%20Blue%20-NoNewline%20%3CBR%20%2F%3E%20Write-Host%20%24resoureGroupName%20-ForegroundColor%20Red%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%24instances%20%3D%20Get-AzureRmResource%20-ResourceGroupName%20%24resoureGroupName%20%60%20%3CBR%20%2F%3E%20-ResourceType%20Microsoft.Web%2Fsites%2Finstances%20%60%20%3CBR%20%2F%3E%20-ResourceName%20%24websiteName%20%60%20%3CBR%20%2F%3E%20-ApiVersion%202018-02-01%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20foreach(%24instance%20in%20%24instances)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20%24instanceName%20%3D%20%24instance.Name%20%3CBR%20%2F%3E%20Write-Host%20%22%60tVM%20Instance%20ID%20%3A%20%22%20%24instanceName%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20try%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20%24processes%20%3D%20Get-AzureRmResource%20-ResourceGroupName%20%24resoureGroupName%20%60%20%3CBR%20%2F%3E%20-ResourceType%20Microsoft.Web%2Fsites%2Finstances%2Fprocesses%20%60%20%3CBR%20%2F%3E%20-ResourceName%20%24websiteName%2F%24instanceName%20%60%20%3CBR%20%2F%3E%20-ApiVersion%202018-02-01%20%60%20%3CBR%20%2F%3E%20-ErrorAction%20Ignore%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20catch%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20continue%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20foreach(%24process%20in%20%24processes)%20%3CBR%20%2F%3E%20%7B%20%3CBR%20%2F%3E%20%24exeName%20%3D%20%24process.Properties.Name%20%3CBR%20%2F%3E%20Write-Host%20%22%60t%60tEXE%20Name%20%60t%60t%3A%20%22%20%24exeName%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%24processId%20%3D%20%24process.Properties.id%20%3CBR%20%2F%3E%20Write-Host%20%22%60t%60t%60tProcess%20ID%20%60t%3A%20%22%20%24processId%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20try%20%7B%20%3CBR%20%2F%3E%20%24processDetails%20%3D%20Get-AzureRmResource%20-ResourceGroupName%20%24resoureGroupName%20%60%20%3CBR%20%2F%3E%20-ResourceType%20Microsoft.Web%2Fsites%2Finstances%2Fprocesses%20%60%20%3CBR%20%2F%3E%20-ResourceName%20%24websiteName%2F%24instanceName%2F%24processId%20%60%20%3CBR%20%2F%3E%20-ApiVersion%202018-02-01%20%60%20%3CBR%20%2F%3E%20-ErrorAction%20Ignore%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20Write-Host%20%22%60t%60t%60tFile%20Name%20%60t%3A%20%22%20%24processDetails.Properties.file_name%20%3CBR%20%2F%3E%20Write-Host%20%22%60t%60t%60tCMD%20Line%20%60t%3A%20%22%20%24processDetails.Properties.command_line%20%3CBR%20%2F%3E%20Write-Host%20%22%60t%60t%60tComputer%20Name%20%60t%3A%20%22%20%24processDetails.Properties.environment_variables.COMPUTERNAME%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20catch%20%7B%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%7D%20%3CBR%20%2F%3E%20%5B%2Fcode%5D%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-392600%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Jun%2026%2C%202018%20Here%20is%20a%20quick%20PowerShell%20scripts%20to%20get%20list%20of%20all%20websites%20in%20your%20Azure%20Subscription%2C%20along%20with%20the%20processes%20running%20within%20each%20website.%3C%2FLINGO-TEASER%3E
Microsoft
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]