Powershell - Adding a number column to an array display

To support me, you can subscribe to the channel, share and like the videos, disable your ad blocker or make a donation. Thank you!

Hello,

You can add a column showing a number for each object in the array display, this can be handy if you’re playing with indexes.

# Example with Get-Process
Get-Process |
Select-Object -Property '#', ProcessName |
ForEach-Object -begin { $i = 0 } -process {
$_.'#' = $i++
$_
}
# You can start at 1 if you prefer
Get-service |
Select-Object -Property '#', Name |
ForEach-Object -begin { $i = 1 } -process {
$_.'#' = $i++
$_
}

Related links