Skip to content

Instantly share code, notes, and snippets.

@jamiegs
Created December 8, 2023 00:55
Show Gist options
  • Save jamiegs/5e3869f26830d2faf4b1e81cdaaf1572 to your computer and use it in GitHub Desktop.
Save jamiegs/5e3869f26830d2faf4b1e81cdaaf1572 to your computer and use it in GitHub Desktop.
Maps the w3p#n to the name of the app pool.
$count = (Get-Process | Where-Object { $_.Name -eq 'w3wp' }).count -1
$var = 1
$result = ''
$id = (Get-Counter "\Process(w3wp)\ID Process").CounterSamples.CookedValue
$app = [regex]::match((Get-CimInstance Win32_Process -Filter "ProcessId = $id").CommandLine, '"([^"]+)"').Groups[1].Value
$result += "w3wp = $id, $app`n"
while ($var -le $count) {
$id = (Get-Counter "\Process(w3wp#$var)\ID Process").CounterSamples.CookedValue
$app = [regex]::match((Get-CimInstance Win32_Process -Filter "ProcessId = $id").CommandLine, '"([^"]+)"').Groups[1].Value
$result += "w3wp#$var = $id, $app`n"
$var += 1
}
$result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment