Functions/FileSizeBelow.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
filter FileSizeBelow {
<#
.SYNOPSIS
    To use as a filter against Get-ChildItem
.DESCRIPTION
    To use as a filter against Get-ChildItem
.PARAMETER Size
    The maximum size a file can be
.EXAMPLE
    Assume I have 1 small file in c:\temp, and many larger files.
 
    dir c:\temp -File | FileSizeBelow -Size 1KB | Select-Object FullName, LastWriteTime, Length
 
    FullName LastWriteTime Length
    -------- ------------- ------
    C:\temp\log.log 12/8/2019 9:55:07 PM 186
.NOTES
    Could NOT make this an advanced function
#>



    param
    (
        [int] $Size
    )

    if ($_.length -le $Size) {
        $_
    }
}