Numbering a list of App Pools

Hello Everyone,

I am by no means a PowerShell guru and could use some help.

I would like to list the available App Pools (Get-IISAppPool) on a server and assign a number (1, 2, 3, etc.) or letter (A, B, C, etc.) to each listed App Pool.

My desire is to be able to list the App Pools for a user and let them select a number or letter, by which the rest of the script would perform an action based on the number or letter selected.

Thanks in advance for your help.

I am not familiar with Get-IISAppPool but assuming it has a name property and that is what you want to show in the list, you can try something like this. The user selects a number so you can use it as index for the array that stores the App Pools, but you must substract 1 because arrays start at 0 and it wouldn’t seem natural to have a menu that starts with 0.

$AppPools = Get-IISAppPool
$Index = 0

$AppPools |
ForEach-Object -Process {
    $Index ++
    Write-Host "$($Index). $($_.Name)"
}

$Selection = Read-Host "`nSelect a number"

$SelectedAppPool = $AppPools[($Selection - 1)]

$SelectedAppPool
1 Like

That works great. Thank you for your help.