You can do that with a For loop, like this:
$Results = Get-ADUser -Filter "name -like '*Joe*'"
For($i = 0; $i -lt $Results.Count; $i++)
{
"{0}. {1} {2} ({3})" -f (1+$i), $Results[$i].GivenName, $Results[$i].SN, $Results[$i].samAccountName
}
That would end up with something like:
1. Joe Dirt (JDirt)
2. Joe Pesci (JPesci)
...and so on. The formatting of the data you want to display is often times the hard part. If you wanted to easily reference that later you should build a hashtable to go with it so that you can easily reference it later.
$Results = @{}
Get-ADUser -Filter "name -like '*Joe*'" |ForEach-Object -begin {$x=0} -process
{
++$x
$Results.Add($x,$_)
"{0}. {1} {2} ({3})" -f ($x), $_.GivenName, $_.SN, $_.samAccountName
}
That would display the same, but later you could reference $Results[2] to work with the Joe Pesci record as it was displayed on the screen.
You didn't ask for it, but I keep a function on hand to make menus like that. I build hashtables like that, then use this:
Function MenuMaker{
param(
[parameter(Mandatory=$true,
ValueFromPipeline = $true)][String[]]$Selections,
[string]$Title = $null
)
$Width = if($Title){$Length = $Title.Length;$Length2 = $Selections|%{$_.length}|Sort -Descending|Select -First 1;$Length2,$Length|Sort -Descending|Select -First 1}else{$Selections|%{$_.length}|Sort -Descending|Select -First 1}
$Buffer = if(($Width*1.5) -gt 78){[math]::floor((78-$width)/2)}else{[math]::floor($width/4)}
if($Buffer -gt 6){$Buffer = 6}
$MaxWidth = $Buffer*2+$Width+$($Selections.count).length+2
$Menu = @()
$Menu += "╔"+"═"*$maxwidth+"╗"
if($Title){
$Menu += "║"+" "*[Math]::Floor(($maxwidth-$title.Length)/2)+$Title+" "*[Math]::Ceiling(($maxwidth-$title.Length)/2)+"║"
$Menu += "╟"+"─"*$maxwidth+"╢"
}
For($i=1;$i -le $Selections.count;$i++){
$Item = "$(if ($Selections.count -gt 9 -and $i -lt 10){" "})$i`. "
$Menu += "║"+" "*$Buffer+$Item+$Selections[$i-1]+" "*($MaxWidth-$Buffer-$Item.Length-$Selections[$i-1].Length)+"║"
}
$Menu += "╚"+"═"*$maxwidth+"╝"
$menu
}
Then it's just:
MenuMaker -Selections ($Results.Values|ForEach("{1} {2} ({3})" -f $_.GivenName, $_.SN, $_.samAccountName) -Title "Choose a user"
And it spits out this:
╔═════════════════════════════╗
║ Choose a user ║
╟─────────────────────────────╢
║ 1. Joe Dirt (JDirt) ║
║ 2. Joe Pesci (JPesci) ║
╚═════════════════════════════╝