If you already have a list of IDs and the script to get the name for a single ID then just use a foreach
to call it for each one. The perf may be bad if the list is large though.
$ids = @(123, 456, 789)
foreach ($id in $ids) {
$result = Get-SPSite ...
# Store whatever data you need from the result associated with the ID it was called against
}
Taking a look at the call they are making though it seems like you could just call it once and then change the filter logic to look in your list instead. This would increase performance but requires that the Get-SPWeb call contain all the IDs you're looking for.
$ids = @(123, 456, 789)
Get-SPSite "http://SharePointserver/sites/TestSite/" | Get-SPWeb -Limit ALL | %{$_.Lists} |?{$ids -contains $_.ID } |ft Title, ParentWebURL, RootFolder
You'll need to play around with the command to get the exact output you want though. At a minimum I suspect you'll want to ensure that the ID is returned back in addition to Title so you can match them up properly.