select second or third object / element

前端 未结 4 1925
我寻月下人不归
我寻月下人不归 2021-01-02 05:51

I want to select the second/third/forth object of a Get-ChildItem statement in my PowerShell script. This gives me the first:

$first = Get-Child         


        
4条回答
  •  死守一世寂寞
    2021-01-02 06:11

    First Item

    gci > out.txt
    Get-Content out.txt | Select -Index 7 | Format-list
    

    Second Item

    gci > out.txt
    Get-Content out.txt | Select -Index 8 | Format-list
    

    The item between n and p

    $n=3 
    $p=7
    $count = 0
    $index = $n+7
    $p=7+7
    while($true){ 
       $index = $index + $count
       Get-Content out.txt | Select -Index $index | Format-list
       if($index -eq $p)
       {    
          break;
       }
       $count = $count + 1 
    }
    

    Note : The first seven lines are empty and the description lines.

提交回复
热议问题