Powershell Get-ChildItem question

Hello All, I am trying to write a short script to make filter and get the full path of the parent folder with "S3080130" in it.  I have tried the followings

Get-ChildItem -Path C:\test-v\ -Directory -Recurse  | Select-String -Pattern S3080130

S3080130 abcde

While if I perform this
Get-ChildItem -Path C:\test-v\ -Directory -Recurse  | FT FullName

Return the followings
C:\test-v\Group3\IVYY2\S3080130 abcde
C:\test-v\Group3\IVYY2\S3080130 abcde\PRM
C:\test-v\Group3\IVYY2\S3080130 abcde\PRM\01 BCK
C:\test-v\Group3\IVYY2\S3080130 abcde\PRM\02 ENG
C:\test-v\Group3\IVYY2\S3080130 abcde\PRM\03 SDR
C:\test-v\Group3\IVYY2\S3080130 abcde\PRM\04 DDR
C:\test-v\Group3\IVYY2\S3080130 abcde\PRM\05 COY
and return all other folders as well

Can I just return the following instead if I only need to filter out S3080130* folder but without its subfolders ?
C:\test-v\Group3\IVYY2\S3080130 abcde

Thanks

Peter

September 7th, 2015 5:22am

Get-ChildItem -Recurse -Path C:\test-v -Directory | ForEach-Object{if($_.name -eq 'S3080130 abcde'){$_.fullname}}


Or, formatted in my favorite code style

Get-ChildItem -Recurse -Path C:\test-v -Directory |
  ForEach-Object{
    if ( $_.name -eq 'S3080130 abcde' ) {
      $_.fullname
     }
   }

Free Windows Admin Tool Kit Click here and download it now
September 7th, 2015 2:57pm

Get-ChildItem -Recurse -Path C:\test-v -Directory | ForEach-Object{if($_.name -eq 'S3080130 abcde'){$_.fullname}}


Or, formatted in my favorite code style

Get-ChildItem -Recurse -Path C:\test-v -Directory |
  ForEach-Object{
    if ( $_.name -eq 'S3080130 abcde' ) {
      $_.fullname
     }
   }

  • Edited by LarryWeiss Tuesday, September 08, 2015 1:22 AM
September 7th, 2015 6:55pm

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

Other recent topics Other recent topics