PS: Unix Shell Tail and Head command equivalents in PowerShell

Here is a quick way of checking through the tail or head contents of files in PS.

Get all contents of a file:

PS C:> Get-Content C:TempServers.txt
Vm1
Vm2
Vm3
PS C:>

Get Head contents of a file:

PS C:> Get-Content -TotalCount 2 C:TempServers.txt
Vm1
Vm2
PS C:>

Get Tail contents of a file:

PS C:> Get-Content -Tail 2 C:TempServers.txt
Vm2
Vm3
PS C:>

Here is a quick way of checking through the tail or head contents of a command result/output in PS.

Get all results of a file: (nothing to be done extra)

PS C:> Get-Process | measure

Count    : 73
Average  :
Sum      :
Maximum  :
Minimum  :
Property :

PS C:>

Get Head/Top items in results :

PS C:> Get-Process | Select-Object -First 3

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
——-  ——    —–      —– —–   ——     — ———–
     40       5     1332        520    16            1456 AEADISRV
     73       8     1428        492    43            1424 armsvc
    140      20    15108      16360    51            8004 audiodg

PS C:>

Get Tail/Last items in results :

PS C:> Get-Process | Select-Object -Last 3

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
——-  ——    —–      —– —–   ——     — ———–
    381      22    13328      10404   254            2344 WmiPrvSE
    286      20     7372       3912   119            1556 wmpnetwk
    106      12     4980       5712    91    44.55   3432 wweb32

PS C:>