Need help displaying Last few results

Hey guys,

I am trying to have my script run through a folder and display back results that meet its criteria. I have been able to do this but now I wanted to add a variable so it would only display the last few hits and not all 100+. Any help is appreciated.

$org = ""
$howmany = ""

while ($org -eq ""){
$org = Read-Host "What is the Org name?"
}
while ($howmany -eq ""){
$howmany = Read-Host "Number of results?"
}
Get-ChildItem C:\ProgramData\JHA\Synergy\SynDocServer -r | ? {$_.psiscontainer -eq $false} | ? {gc $_.pspath |select-string -pattern "$org"  select -last "$howmany"  }
  • Edited by nucksin11 15 hours 25 minutes ago
September 1st, 2015 11:29am

Please edit your post and post your code via the 'Insert Code Block' button.

Free Windows Admin Tool Kit Click here and download it now
September 1st, 2015 11:33am

You're not piping through Select-Object in the correct place. Move it outside of the last where.
September 1st, 2015 11:49am

Hello,

Please edit your last line to this and give a try, again this sorting is not with Last Written time but sorted with String...

Get-ChildItem C:\ProgramData\JHA\Synergy\SynDocServer -r| ? {$_.psiscontainer -eq $false}|where {$_.Name -match "$org"} | select -Last $howmany

to sort with Last Write Time, added sort

Get-ChildItem C:\ProgramData\JHA\Synergy\SynDocServer -r | ? {$_.psiscontainer -eq $false}|where {$_.Name -match "$org"} |sort  LastWriteTime  | select -Last $howmany

btw, good script convert it to function it would be easier to manage and use.

Regards,

Free Windows Admin Tool Kit Click here and download it now
September 1st, 2015 10:38pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics